我正在尝试读取我在 Paint.net 中创建的文件的 TGA 标头。它似乎有什么问题。如果我使用规范中的标头结构,例如:
typedef struct {
CHAR idlength;
CHAR colourmaptype;
CHAR datatypecode;
WORD colourmaporigin;
WORD colourmaplength;
CHAR colourmapdepth;
WORD x_origin;
WORD y_origin;
WORD width;
WORD height;
CHAR bitsperpixel;
CHAR imagedescriptor;
} TGAHEADER;
我明白了:
Data size: 0
Color Map type: 0
Data Type code: 2
Bits per-pixel: 0
Size: 501 x 2080
这是错误的,因为我的图像是 501x501,每像素 32 位。但是,如果我从结构中注释掉两个字节,fe this one colourmaporigin
,我会得到:
Data size: 0
Color Map type: 0
Data Type code: 2
Bits per-pixel: 32
Size: 501 x 501
哪个是对的。我正在阅读我在这种文件格式上找到的所有内容。它从来没有说这些字段中的任何一个都是可选的。
我怎么会得到这样的结果?
下面是读取数据的代码:
void Image::readTGA()
{
TGAHEADER fileHeader;
std::ifstream fileHandle(fileName, std::ios::binary);
if (fileHandle.is_open())
{
fileHandle.read((char*)(&fileHeader), sizeof(TGAHEADER));
fileHandle.close();
}
else
{
std::cout << "An error occured when opening a file." << std::endl;
}
}
我正在使用 VS2015,针对 x86 平台。