Robert Weindl
Robert Weindl

Reputation: 1092

Problems with the BITMAPFILEHEADER

I just started to learn more about the .bmp file format and wrote a small C++ programm.

Here is an excerpt of my code:

FILE* imageFile;
fopen_s (&imageFile, this->GetImagePath (), "rb");

fread (&this->bmfh, sizeof(BITMAPFILEHEADER), 1, imageFile);    
std::cout << bmfh.bfSize << " " << bmfh.bfOffBits << " " << std::endl;

According to the MSDN bmfh.bfSize should return the size of the bitmap file.

But in my case bmfh.bfOffBits (54) is higher than bmfh.bfSize (14)? What could be the reason? Because my idea was to allocate memory for the image data in this way:

this->size = bmfh.bfSize - bmfh.bfOffBits;
pixelData = new BYTE[this->size];

Upvotes: 0

Views: 2384

Answers (1)

Neigyl R. Noval
Neigyl R. Noval

Reputation: 6038

bmfh.bfOffBits (54) - is the size from the start of the file to the actual RGB data of the bmp file. This is usually equal to 54.

That is, from offset 0 (from start of file) to offset 53 is the header of the bmp file. So that from offset 54 onwards is the actual RGB pixel data of the image file.

bmfh.bfSize (14) - is the actual size of the image.

I try googling on this matter and this is the best source I've found.

http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html

Upvotes: 1

Related Questions