开发者

Bitmap Image Output in C

开发者 https://www.devze.com 2023-02-11 17:47 出处:网络
I\'m working on small project in C and at one point, I need to write a picture with the content of an array to a file. This will have to run on an embedded system at some point, so additional librarie

I'm working on small project in C and at one point, I need to write a picture with the content of an array to a file. This will have to run on an embedded system at some point, so additional libraries are not an option.

The code I have so far works (in a modified version) for RGB, but fails for 8bit Grayscale.

This is a stripped down version of the code so far: http://paste开发者_如何学Gobin.com/U1UYAPuT

As I strongly suspect the header to be broken in some way, my question comes down to: What is a correct header for a BMP file for 8Bit Grayscale?


Your code would be a lot simpler if you ditched BMP and wrote images as PGM files instead. The format is a lot more portable and easy to work with in code. Both formats are uncompressed so data rates would be about the same. The only thing you would lose would be the ability to view the images natively on Windows systems -- whether or not this is a big deal depends on your requirements.

Here are some examples.

EDIT

At the very least, if you write your images in PGM and broken BMP, you can use imagemagick to reliably convert the PGM to a working BMP. Then compare the headers of the working and broken BMP images using a binary diff tool and fix your BMP writer, if required.

0

精彩评论

暂无评论...
验证码 换一张
取 消