wrong BMP files?

M

Marcin P

When you build a 24-bit BMP file (without compression), its size should be:
width*height*bitperpixel+54bytes (54 bytes from file and bitmap headers).

When I create BMP files in MS Paint in "non-standard" dimensions
(different than 1024x768 or 512x384) sizes of files are bigger than they
sholud be.
When dimensions are standard everything is OK.

Example from Paint:
white picture->173x14->save as 24bit BMP...
and size written in bitmapfileheader is 7334 bytes... but it should be
173*14*3+54=7320. The difference is 14 bytes. Why?

When dimensions are 100x100 or 1024x768 - everything is OK.
 
J

Jakob Bieling

Marcin P said:
When you build a 24-bit BMP file (without compression), its size
should be: width*height*bitperpixel+54bytes (54 bytes from file and
bitmap headers).
When I create BMP files in MS Paint in "non-standard" dimensions
(different than 1024x768 or 512x384) sizes of files are bigger than
they sholud be.
When dimensions are standard everything is OK.

Example from Paint:
white picture->173x14->save as 24bit BMP...
and size written in bitmapfileheader is 7334 bytes... but it should be
173*14*3+54=7320. The difference is 14 bytes. Why?

When dimensions are 100x100 or 1024x768 - everything is OK.

In bitmaps, each scanline (ie row of pixels) must be dword aligned.
To achieve that, padding is added, if neccessary. i you have 173 pixels
in widthwith 3 bytes per pixel, you have a total of 519 bytes per
scanline. Now the next dword boundary is 520, so you have to add1
padding byte. Do that for all 14 scanlines and you have the difference
of 14 bytes.

hth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top