Click to See Complete Forum and Search --> : Bitmap Format


answer
May 8th, 2004, 11:35 PM
I read an article on the bitmap format. I learned it and able to use it :). Just one problem. I opened windows paint drew something, saved, and when I open with my program the bitmap is correct exept after it it has some random colors :confused:.

Heres my code

void OpenBMP(DIBSTRUCT *dib, HANDLE f)
{
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;
FileRead(f, &bmfh, sizeof(BITMAPFILEHEADER));
InitDib(dib);
FileRead(f, &bmih, sizeof(bmih));
CreateDib(dib, bmih.biBitCount, bmih.biWidth, bmih.biHeight); // Function I made for CreateDibSection
FileRead(f, dib->lpBits, bmih.biWidth*bmih.biHeight*(bmih.biBitCount>>3));
}


Anyone know how I may load the Bitmap Properly?

Thanx in advance!

answer
May 9th, 2004, 03:48 PM
I found out how to fix it :). By changing the line

FileRead(f, dib->lpBits, bmih.biWidth*bmih.biHeight*(bmih.biBitCount>>3));
to
FileRead(f, dib->lpBits, bmih.biSizeImage);

Why is the image size is greator than my calculations. The image is 24bit :confused: ...
24 >> 3 = 3bytes.
The hight is 28 and width 85. 85*28=howmany pixels there are each pixel is 3 bytes so the formula to express the total size should be 85*28*3. But that is not equal to "biSizeImage" :(. After experemnting with BMP format images I found out that the bitmap size is (bitcount >>3 )*width*height+height (assumming 24bit bitmap. Why is height added? ( Iam currently working with 24bit images)

Thanx in advance!