I m following this tutorial http://www.gamedev.net/page/resources/_/technical/game-programming/how-to-load-a-bitmap-r1966 and I got the problem of wrong value for all the bitmap header/info that I load.
I ve宣布了储存光标头的结构。
typedef struct BITMAPFILE_HEADER {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BITMAPFILE_HEADER;
//Bitmap information header
//provides information specific to the image data
typedef struct BITMAPINFO_HEADER{
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFO_HEADER;
//Colour palette
typedef struct RGB_QUAD {
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
} RGB_QUAD;
之后,我通过使用以下代码读了比图:
FILE *in;
in = fopen("picture.bmp", "rb");
if (in == NULL)
{
printf("Error opening file
");
}
else
{
BITMAPFILE_HEADER bmfh;
BITMAPINFO_HEADER bmih;
fread(&bmfh, sizeof(BITMAPFILE_HEADER), 1, in);
fread(&bmih, sizeof(BITMAPINFO_HEADER), 1, in);
if (bmih.biBitCount != 24)
printf("not 24");
}
我的情况是24点,但当我管理这一方案时,它显示“不是24点”。 我试图在视觉演播室一中进行推测,然后看到<条码>bmih.biBitCount<0>。 此外,图像宽度和高度也是错误的,我在头部发现的唯一正确数据是bmfh.bfType
。 页: 1
Anyone know what s wrong with my codes? Again, I just want to read the bmp but not displaying it.
PS: Originally the picture is in JPEG format. I converted it to BMP format by using MS PAINT and re-save it in BMP format. I wonder does it affect the values?