8
votes

i'm new to this field ,and i get confused between some terms!

bisizeimage, bisize and bfsize!

please i need a simple definitions for each one, and if there is equations to calculate them ?

edited : ("answered by friend")

biSize > The number of bytes required by the structure. (what is the structure exactly ?)

The structure is the struct BITMAPINFOHEADER. That is a fixed value.

biSizeImage > The size, in bytes, of the image. bfSize > The size, in bytes, of the bitmap file. (what is the difference between image & bitmap file ?)

biSizeImage is the whole image size, bfSize is the same, but you have to add the size of the 2 header files.

4
what is the context? can you add a bit of more info?bitoiu
sure thanks for replaying :)Osama Nsr

4 Answers

12
votes

@Roman Abashin's answer has a slight but important error. biSize is not the combined size of both headers.

biSize is the size of the BITMAPINFOHEADER only. It is 40 bytes.

biSize = 40

The combined size of both headers is actually bfOffBits (you can think of the "Off" as referring to the offset of the actual bitmap from the beginning of the headers - remember, the bitmap comes straight after the headers).

bfOffBits = 54

Therefore all the following are correct formulas for bfSize:

bfSize = biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)
bfSize = biSizeImage + sizeof(BITMAPFILEHEADER) + biSize
bfSize = biSizeImage + 14                       + 40
bfSize = biSizeImage + 54
bfSize = biSizeImage + bfOffbits

And @Roman Abashin's formula for biSizeImage, the size of the actual bitmap, is correct for a 24-bit bitmap.

Confusingly, biSize, bfOffBits, bfSize and biSizeImage are all in units of bytes, whereas biWidth and biHeight are in units of pixels. The number of bytes per pixel is defined in the biBitCount part of the header. It is 3 bytes (or 24 bits) for a 24-bit bitmap.

Note that bfOffBits's units are in bytes and biBitCount's units are in bits.

More detail can be found on Microsoft's pages:

Info on BITMAPFILEHEADER

Info on BITMAPINFOHEADER

Edit: I added some annotations to the bitmap overview below to clarify things even more![layout of bitmap and headers with size information Edit: Changed biSizeImage + 24 (etc etc) to + 14.

9
votes
bfSize = biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)
bfSize = biSizeImage + 54               

// since BITMAPFILEHEADER = 40 and BITMAPINFOHEADER = 14 

biSizeImage = (biWidth * sizeof(RGBTRIPLE) + padding) * abs(biHeight) 
1
votes

One tiny typo, in @Shock451 answer. According to: https://en.wikipedia.org/wiki/BMP_file_format the values of BITMAPFILEHEADER and BITMAPINFOHEADER are swapped.

there Should be:

// since BITMAPFILEHEADER = 14 and BITMAPINFOHEADER = 40

not:

// since BITMAPFILEHEADER = 40 and BITMAPINFOHEADER = 14
1
votes

bfSize is the full file size of the bitmap image the file size of a bitmap image is made up of two parts:

  • a header part (with general information regarding the file = bfOffBits)
  • and the image part (where the pixel information is stored = biSizeImage)

Therefore, we have the following structure

bfSize = bfOffBits + biSizeImage 

Futhermore, bfOffBits (the header part) can be further broken up into

  • a file header and
  • an info header (biSize)

Therefore, it can be also written as

bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + biSizeImage

Since (by today's BMP definition) the size of BITMAPFILEHEADER is exactly 14 bytes and the size of BITMAPINFOHEADER is exactly 40 bytes this could also be written as

bfSize = 14 + 40 + biSizeImage

or

bfSize = 54 + biSizeImage

However, this would be bad practice, as hardcoding 'magic numbers' is generally frowned upon.

But let's look at biSizeImage. The file size of the image itself is made up, generally speaking, by the color depth * width * height. The color depth in a 24-bit BMP is 3 bytes per pixel (0-255 values for blue, green, red, respectively) — a so called RGB triple. Additional info for experts: the values for the three colors are saved in the order of blue, green, red — search the keyword LittleEndianness for further info on that topic. The BMP standard also adds 0's as padding if the width of the image is not divisble by 4 bytes.

Slightly confusingly, as others have pointed out, you now have to multiply the size in pixels with the depth in bytes. Therefore, we have

biSizeImage = (biWidth * sizeof(RGBTRIPLE) + padding) * abs(biHeight) 

which will give you the final size in bytes of the image.

So, to conclude:

  • biSizeImage = the file size in bytes of the image part of a BMP
  • biSize = the file size in bytes of the info header part of a BMP header
  • bfsize = the file size in bytes of the full BMP (including both header and image itself)

A nice overview of the structure of a BMP can be found here

Edit: Added correction (thanks to @MotherBrain)