Sign in to follow this  

Programming with the bitmap file format

This topic is 3662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm not sure if this is the right place to ask this but I couldn't think of anywhere else. I'm writing an app where I'm wanting to convert raw byte data into bitmaps. I did a bit of reading about the bitmap file format before I attempted writing this and I've created an app which spits out the two headers required, the palette (I'm converting the data into an 8bit image with an indexed palette) and then the data. Because it's 8bpp I can just write the raw data out, with one exception. Every scan line in a bitmap needs to be divisible by 4 bytes (32 bits). So I just mod the width of the image by four and then stick on that many zeros at the end of each line. This works absolutely perfectly for images whos width is an even number. But as soon as I try and give it an image with an odd numbered width it doesn't work. The image in question is 17 pixels by 9 pixels. So my app sticks a single byte on the end of each row to top it up to 18, which I would imaging was correct. Everything seems to be correct when I read in the converted image in a hex editor. The headers are correct and the data seems correct in that it's exactly the same as the raw data except it has an extra byte after every 17 pixels. I've spent ages trying to find out what the problem is and in the end I opened the raw data in paint shop pro and saved it out as an 8bpp bitmap with the correct palette and analysed this in my hex editor. Now, it seems that PSP sticks THREE bytes on the end of each row, instead of one. Why on earth does it do this? I've read numerous articles on the BMP file format and I can't find out why this is so but I think this could be part of my problem. Does anyone have any idea?

Share this post


Link to post
Share on other sites

This topic is 3662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this