Computer Science Canada Bitmap parsing |
Author: | Insectoid [ Sun Apr 17, 2011 7:42 pm ] | ||
Post subject: | Bitmap parsing | ||
I'm working on a program to manipulate bitmap files. So far, all I've done is read in the headers (file header + bitmap info header). The data reads in correctly until the height field is read. My test image is 50x50. Width is correctly read as 50, whereas height is read as -50. All following fields are 0, but shouldn't be. Anyone know what's up? The code is a bit messy. I'll clean it up when it works.
|
Author: | DemonWasp [ Sun Apr 17, 2011 8:36 pm ] |
Post subject: | RE:Bitmap parsing |
On the Wikipedia page for the BMP file format, I found: Wikipedia wrote: ImageHeight is expressed in pixels. The absolute value is necessary because ImageHeight can be negative.
This is in the section entitled "Pixel Storage". Just take the absolute value. |
Author: | Insectoid [ Sun Apr 17, 2011 8:40 pm ] |
Post subject: | RE:Bitmap parsing |
Ah, that makes sense. Looked at the file in a hex editor and confirmed that the height is indeed negative, and all following fields are indeed zero. So my code's working fine. |
Author: | Alexander_ [ Sat May 14, 2011 6:46 pm ] |
Post subject: | RE:Bitmap parsing |
A little late, although I hope it could be useful to you. The pixel array of the bitmap is stored in reverse (according to the image) order and will cause the rendered image (if directly taken from the array) to be rendered upside down. A negative height can just mean for it to be read right side up (and you should handle this fact in your code if you wish to cover all edge cases) |
Author: | Insectoid [ Sat May 14, 2011 8:17 pm ] |
Post subject: | RE:Bitmap parsing |
Yeah, you're a bit late. I've figured this all out and finished the project. |