Archived

This topic is now archived and is closed to further replies.

Mardigin

biSizeImage equals 0

Recommended Posts

I am trying to load a bmp that I made in photoshop. The bmp is an 8 bit 256 color RLE 640 X 480. Now when I dump the BITMAPINFOHEADER to a txt file I get the following. BITMAPINFOHEADER ........... paddingbiBitCount : 8 biClrImportant : 0 biClrUsed : 0 biCompression : 0 biHeight : 480 biPlanes : 1 biSize : 40 biSizeImage : 0 biWidth : 640 biXPelsPerMeter : 2834 biYPelsPerMeter : 2834 Closing Error Output File. As you can see the biClrImportant, biClrUsed, biSizeImage are all equal to 0; unlike when I load a bmp created in photoshop. Photoshop bmp BITMAPINFOHEADER BITMAPINFOHEADER ........... biBitCount : 8 biClrImportant : 256 biClrUsed : 256 biCompression : 0 biHeight : 480 biPlanes : 1 biSize : 40 biSizeImage : 307200 biWidth : 640 biXPelsPerMeter : 2834 biYPelsPerMeter : 2834 Closing Error Output File. So now when I want to allocate the memory and read the file, I am screwd! // allocate the memory for the image if (!(bitmap->buffer = (UCHAR *)malloc(bitmap->bitmapinfoheader.biSizeImage))) { // close the file _lclose(file_handle); // return error return(0); } // end if // now read it in _lread(file_handle,bitmap->buffer,bitmap->bitmapinfoheader.biSizeImage); Does anyone know what I am doing wrong? I am extracting the BITMAPINFOHEADER like this.... _lread(file_handle, &bitmap->bitmapinfoheader,sizeof(BITMAPINFOHEADER));

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Well, first off.. it doesn''t appear to have RLE compression: biCompression = 0.

Second, you can allocate the memory by doing this..

NeededMemory = biWidth*biHeight*(BitsPerPixel>>3);

I''ve only really ever worked with my own bitmap loading functions, so I''m not sure exactly how the BITMAPINFOHEADER is setup, and what it has in it... but it should have the width/height/bitdepth in it.

Billy - billyB@mrsnj.com

Share this post


Link to post
Share on other sites
Yay!!!

Thank you very much Billy. this NeededMemory = biWidth*biHeight*(BitsPerPixel>>3); worked perfectly for figuring out the image size.

Thank you a bunch!!!

I wonderwhy the biSizeImage was 0 for my bmp though? Does anyone have the answere for this?

Share this post


Link to post
Share on other sites
Photoshop is a fairly strange program. Internaly it uses X pixels per meter, and y pixels per meter to determine the width, height and size of an image. Most image editing programs do not have a problem with this, they usualy don''t rely on the size being correct. They determine the size by either the height/width or by the x & y pixels per meter. This gives a more accurate representation of the data.

Share this post


Link to post
Share on other sites