Hi, guys. I've been reading your forum for some time.
Now I need a little help again.
I am trying to read a bitmap file using BITMAPFILEHEADER, BITMAPINFOHEADER and RGBQUAD in windows.h - I need RGB values or only one of them. All the info in header structures is OK. My file has no compression(I drew 4 pixels with paint).
void ReadBitmap(char* FileName)
{
RGBQUAD Palette[4];
BITMAPFILEHEADER bitmapFileHeader;
BITMAPINFOHEADER bitmapInfoHeader;
FILE *stream=fopen(FileName,"rb");
if(stream ==NULL)
printf("ERROR: Can’t open “<<FileName<<endl;");
else
{
if((fread(&bitmapFileHeader,sizeof(BITMAPFILEHEADER),1,stream)) == -1)
printf("ERROR: Can’t Read Fileheader Stucture!”;");
if ((fread(&bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, stream) == -1))
printf("ERROR: Can’t Read Infoheader Stucture!”;");
}
printf("compr - %d\n", bitmapInfoHeader.biCompression);
printf("width - %d\n", bitmapInfoHeader.biWidth);
printf("height - %d\n", bitmapInfoHeader.biHeight);
RGBQUAD pixel;
for(int l=0;l<4;l++)
{
if((fread(&pixel,sizeof(RGBQUAD),1,stream))==-1)
{printf("<<“ERROR: Can’t read bitmap’s color palette!”;"); }
else
{
printf("/r - %d",int(pixel.rgbRed));
printf("/g - %d",int(pixel.rgbGreen));
printf("/b - %d",int(pixel.rgbBlue));
printf("/off - %d\n", pixel.rgbReserved);
}
}
I got following result
compr - 0
width - 4
height - 1
/r - 237/g - 28/b - 36/off - 36
/r - 21/g - 237/b - 28/off - 0
/r - 228/g - 176/b - 136/off - 239
/r - 228/g - 176/b - 136/off - 239
RGB values for the first pixel are OK, but then I got something in rgbReserved when it should be 0. The next values(including reserved) are mixed rgb values for the next 3 pixels.
if I understand bitmap file format correctly, the result should be something like this :
/r - 237/g - 28/b - 36/off - 0
/r - 237/g - 28/b - 36/off - 0
/r - 136/g - 0/b - 21/off - 0
/r - 239/g - 228/b - 176/off - 0
Can you tell me where I am wrong?