Specifies that the pixel data of a BMP file is stored on a row, and that the number of bytes per line must be a multiple of 4, if the actual pixel data is not a multiple of 4? This requires byte alignment, which is a multiple of 4 bytes to be added at the end of a line.
(biwidth*bibitcount+31)/32*4*biheight//where biwidth is the width of the image in pixels, biBitCount is the number of bits per pixel, such as a black-and-white image (not grayscale, or black or white) of 1 pixels 1 bits, 16 color is 4 bit, true color is 24 bit
... biheight refers to the height of the image.
(biwidth*bibitcount+31)/32*4 is the actual number of bytes to derive a row. Multiplied by Biheight is the total size.
Here's an example of how to align (reach multiples of 4):
Biwidth=1
Bibitcount=1
Biwidth*bibitcount=1; Less than 1 bytes, so make up 4 bytes
1+31=32 (BIT),
(1*1+31)/32=1, notice why this is divided by 32? is because 4 bytes = 32 bits, the other angle is the total number of 4 bytes,
The final line of bytes is: 1*4=4 bytes,
biwidth=52
Bibitcount=1
biwidth*bibitcount=52*1=52
(52*1+31)/32=2 2 x 4 bytes per line
The final number is multiplied by 4, namely:
2*4=8, which is 8 bytes per line when the width is 52 pixels and 1 bits per pixel are stored
Again:
biwidth=111
bibitcount=24//is True Color
biwidth*bibitcount=111*24=2664 (BIT)
2664/(4*8) =2664/32=83 8 bit, certainly can't put these 8 bit out of storage, in fact, the purpose is to add the end of the 8 bits 24 0 full 32 bits (that is, 4 bytes), so:
(biwidth*bibitcount+31)/32= (2664+31)/32=2695/32=84 (4 bytes), that is, 84 4 bytes of storage, so you will end up multiplying by 4:
(biwidth*bibitcount+31)/32*4=84*4=336 (bytes)
.....................................
Note that you cannot write 31 to 32, and if you write 32 it will make a mistake like this:
Biwidth=32
Bibitcount=1
(biwidth*bibitcount+32)/32*4=64/32*4=8 only need 4 bytes, the result is 8.
Must not be small, such as 30, then when:
Biwidth=1
Bibitcount=1
(biwidth*bibitcount+32)/32*4=0 must be wrong,
It is also important to note that
(biwidth*bibitcount+31)/32*4 cannot be written (BIWIDTH*BIBITCOUNT+31)/8 because '/' is the meaning of rounding
So: (biwidth*bibitcount+31)/32*4 not equal to (biwidth*bibitcount+31)/8, do not believe you give an example to try.
Remember: (biwidth*bibitcount+31)/32 is the key, which means how many (4 bytes) It takes to multiply this result by 4 The result is definitely a multiple of 4.
Why is the bisizeimage of a 24-bit bitmap (true color) not equal to (biwidth*bibitcount+31)/32*4*biheight?