views:

173

answers:

7

I am wondering how I can both import and export bitmaps to and from C. I'm basically lost on where to begin.

A: 

The term "bitmap" is somewhat generic, unless you specifically mean a Windows BMP.

I'd recommend using an image processing library on your platform (like gd). A good graphics library has routines to do input and output with images in various formats.

Seth
+2  A: 

Have you taken a look at ImageMagick's C API wrapper, MagickWand? Here's the documentation if you want to peruse.

John Feminella
+2  A: 

A bitmap in memory looks similar to this:

struct Image {
    int width;
    int height;
    char *data;    // 1 byte per channel & only 1 channel == grayscale
}

struct Image theImage;
theImage.width = 100;
theImage.height = 100;
theImage.data = malloc(sizeof(char) * theImage.width * theImage.height);

As to importing and exporting, there are some really simple file formats out there, take a look at BMP. For more complex formats you best use an already available library.

Most frameworks already have load/save methods for the most common fileformats. You could take a look at SDL if you're looking for a lightweight library.

Georg
A: 

I like using SDL with the dummy driver. You can draw onto an in-memory buffer just like you would onto a screen, then save it out to a PNG or whatever with SDL_image or similar.

Another popular library for this is GD.

Warren Young
+1  A: 

The simple answer is to use an appropriate library. What library is appropriate will depend on what platform you are using. On a GUI platform the GUI API/Framework will include these facilities.

Clifford
A: 

FreeImage is excellent. I've used this for my own game development work, and it supports tons of formats. Here's the list of features and formats supported - http://freeimage.sourceforge.net/features.html

Jim Buck
I had a look at the 100-page API manual, and I'm not sure this is the source for someone who's having trouble getting started...
Norman Ramsey
A: 

I like the netpbm/pbmplus tools, although I usually like the command line; the API is efficient but not much fun to use.

This semester I wrote a significant amount of software for beginning students to use to manipulate images; you might want to check out the homework assignments and supporting software for the Tufts course Machine Structure and Assembly-Language Programming.

Norman Ramsey