Question

I am trying to analyze license plates with C++ code. The point is NOT how to get there fast, because I want to go to the process of creating this C++ code myself and learning how to.

Problem:

The bytes in the bitmap file don't add up! The bitmap file: enter image description here http://ictmdeklerk.nl/cor.bmp

Why they dont add up:

I am using 24 bit bitmap images (*.BMP files). I know the bitmap is constructed with the BMPFILEHEADER, and BMPINFOHEADER, which togehter consume 54 bytes.

Now, the image is 1350 pixels wide and 740 pixels high, which results in 999000 pixels.

Because the file is 24 bit, there are 3 bytes per pixel. 999000 * 3 = 2997000 bytes neccessary for the image. But the image size (biSizeImage) in the BMPINFOHEADER says the image is 2998480 bytes! The file size is 2.998.534 bytes - 54 header bytes = 2.998.480 indeed. So the header is still 54 bytes. No extra meta data there. When I divide 2.998.480 / 3 bytes per pixel I get 999493,33 pixels! It is not even a round number!

It is driving me insane. How does windows ever know how to show this image without shifting pixels or colors or anything?

Can anyone explain me where these extra pixels/bytes come from? And how to deal with them?

Thanks in advance!

Was it helpful?

Solution

BMP files pad each row to 4-byte boundaries.

Your image is

(1350px wide) x (3 bytes per pixel) = 4050 bytes per row. 4050 is not divisible by 4, but 4052 is so 2 bytes for every row (2 * 740 = 1480 bytes) are added as padding to your image.

The file size is therefore 2997000 image bytes + 54 bytes header + 1480 bytes row padding = 2998534 bytes, which is the actual file size.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top