Resize a bitmap in CS50 of Harvard's Set 4 -


i find bitmap provided followed properties.

{bisize = 40, biwidth = 3, biheight = -3, biplanes = 1, bibitcount = 24, bicompression = 0, bisizeimage = 36, bixpelspermeter = 2834,   biypelspermeter = 2834, biclrused = 0, biclrimportant = 0} 

my question why bisizeimage is't 3 * 3 * 3 = 27 ?

bisizeimage: total size of image in bytes including pixels , padding.

you have biwidth = 3 pixels, bibitcount = 24 bitperpixel (8bits = 1byte)

so image width: 3pix * (24 / 8 ) bytesperpixel = 9 bytes 9 bytes not multiple of 4, , bmp files have have row width multiple of 4.

so closest number 4x 12 bytes. means in each row, add 3 bytes of zeros 0x00 0x00 0x00.

now total size be: 3pix * (3bytes per pixel) + padding 3 bytes = 12 bytes per row 12 bytes per row * 3 rows = 36 bytes hope helps. z


Comments