Question

Does anybody know a good C sample that loads bitmaps and handles all the cases: rle, b/w bitmaps, so on?

Code should be cross-platform.

Thanks.

Was it helpful?

Solution

I would suggest using a library like SDL image

OTHER TIPS

If you are looking for a minimal bmp loader this link will give you all you need to know about the BMP format, data structures and sample code without any library dependency to load:

http://paulbourke.net/dataformats/bmp/.

It also contains code to see the loaded BMP in a open gl texture, so pretty much all you need...

Chris Backhouse made a functional little BMP loader (with an eye to using them as OpenGL textures). It's C++, not C, and he admits it's not cross platform. However, it's small and easy to understand, so I thought I'd add the link here:

http://users.ox.ac.uk/~orie1330/bmploader.html

You need some external library to do this (I recommend ImageMagick). The ImageMagick web site also includes documentation and examples.

Check out for OpenCV Library developed by Intel .

If you are tied to the BMP file format, it's pretty simple to look at the header yourself and get the pixels. See this google search. One of the more interesting matches is here. The most counter-intuitive part is that every line of pixels is 4-byte aligned. Also, watch out for compressed BMPs... (My experience is that many third-party tools have trouble with compressed BMPs, so maybe some libraries you encounter will also..)

If you aren't tied to the BMP file format, I recommend libpng. The manual provides some sample code which is pretty clear.

As others suggested you might want to use an external library like SDL. If you want to learn something and do it yourself, see my answer to this very similar question: Getting RGB values for each pixel from a 24bpp Bitmap for conversion to GBA format in C where you'll find C code which prints out each pixel, and have a look at the wikipedia page about bmp files, because it's very good.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top