Search code examples
c++bmp

Eliminating two zeros in a bmp array


I was trying to load BMP picture into memory and save the RGB array into a file(my own format 3d model with texture data).I made the programming to convert OBJ and its texture data into a m2d file. But when I loaded the file in actual in my m2d loader it showed me green continuous lines on the picture.

I opened the BMP file in hex editor, found two 00s as culprit(occurred many times). Any hint how should I take these 00s out of my RGB array? Any hint or tip will be appreciated.


Solution

  • Each horizontal row in a BMP must be a multiple of 4 bytes long.

    If the pixel data does not take up a multiple of 4 bytes, then 0x00 bytes are added at the end of the row. For a 24-bpp image, the number of bytes per row is (imageWidth*3 + 3) & ~3. The number of padding bytes is ((imageWidth*3 + 3) & ~3) - (imageWidth*3).