what is the difference between bisizeimage , bisize and bfsize?

后端 未结 4 1200
失恋的感觉
失恋的感觉 2021-02-15 11:26

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

bisizeimage, bisize and bfsize!

please i need a s

4条回答
  •  灰色年华
    2021-02-15 11:45

    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)

提交回复
热议问题