A major annoyance for me is saving images from c++. I can’t really find any libraries that I like, they are either too complex for the task or they don’t do what I want them to do. So I have created my own, extremely lightweight image library.

All you need to run this is two files, the cpp file and the header. I chose .tga because it is one of the easiest, straightforward formats to save to.

Here is some example code of saving an image with this library:

    #include "Image.h"

    int main(int argc, char **argv) {
       //declare image
       short width = 256;
       short height = 256;

       TGAImage *img = new TGAImage(width,height);

       //declare a temporary color variable
       Colour c;

       //Loop through image and set all pixels to red
       for(int x=0; x<width; x++)
          for(int y=0; ysetPixel(c,x,y);
          }

       //write the image to disk
       string filename = "/Users/daniel/test.tga";
       img->WriteImage(filename);

       return 0;
    }

This outputs a red image like so:

Anyway, have fun using this in your projects, Here is the download link for the source: Download For more information on the TGA file format visit the following links: http://paulbourke.net/dataformats/tga/  http://en.wikipedia.org/wiki/Truevision_TGA