I'm working on a program to resize a BMP file and store it in a new file. I noticed that some BMPs are stored totally upside-down while others are just stored upright. So I made two solutions to handle both cases. My question is How to know if the BMP is stored upright or upside-down beforehand? So that I can decide which solution to use instead of trying both solutions with every BMP!
They are upside-down for compatibility with OS/2 Presentation Manager. It can actually be either, top line first bitmaps have a negative height. @HansPassant, the ability to have a negative height is a feature added well after the bitmap format was popularized.
The order of the pixels in BMP file is as follows: from left to right, from bottom to top (first pixel is from lower left corner of the picture). In the first approach, the picture can be displayed upside down, just to test the reading data from memory.
The BMP format is an uncompressed raster file designed to display high-quality images on Windows and store printable photos.
BMPs use a very simple form of compression called Run Length Encoded (RLE). Instead of storing a value for each pixel RLE stores a number, N, followed by an index. This means that the next N pixels are of the color for this index.
The answer lies within the BITMAPINFOHEADER-structure.
From: http://msdn.microsoft.com/en-us/library/windows/desktop/dd318229(v=vs.85).aspx
For uncompressed RGB bitmaps, if biHeight is positive, the bitmap is a bottom-up DIB with the origin at the lower left corner. If biHeight is negative, the bitmap is a top-down DIB with the origin at the upper left corner.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With