HOME | DOWNLOAD | DOCS | DEVELOPMENT | LICENSE | CREDITS |
Welcome to the imagen API documentation.
imagen is a simple, object-oriented imaging library designed for easy encoding/decoding of images.
It provides semi-advanced reading and writing capabilities for common image file formats for use in virtually any software application.
Using imagen is pretty simple. The following code will show you some basic operations such as reading and writing images.
Reading and writing:
#include <imagen/iImage.h> using namespace imagen; // Read an image from disk iImage image("input.tga"); // Save the image to disk image.save("output.png");
That's all there is to it! No tedious intialization or set up required, and the memory is automatically cleaned up at destruction.
If you want more control over how the image is saved, you can create objects for specific image file formats:
#include <imagen/iTGA.h> using namespace imagen; // Create a Targa object iTGA targa; // Load a Targa image file targa.load("input.tga"); // Adjust some TGA settings targa.setTargaVersion(iTGA::v2_0); targa.enableRLE(true); targa.setImageID("This image was written using the imagen library"); // Save the image targa.save("output.tga");
You can also load images from, and write images to, existing memory buffers:
#include <imagen/iImage.h> #include <imagen/iRoutines.h> using namespace imagen; int width = 800; int height = 600; int bpp = 3; // Create a memory buffer Iubyte *data = iAlloc(width*height*bpp); // Fill buffer with image data... ... // Create a PNG image from buffer // When images are created in this fashion, you must delete the memory // buffer when you're finished with it. You allocate memory, you delete memory. iPNG ipng(data, width, height, iRGB, bpp); // Modify image data here if you like ipng.fill(iColor(25, 140, 255)); // Write PNG image file ipng.save("mypicture.png"); // Don't delete data yet because we're still using it // Create a TGA image from buffer iTGA itga(data, width, height, iRGB, bpp); // Create an output memory buffer // I multiplied the total image size by 2 to give the TGA writer plenty // of room to write all the file format-specific data as well. // It's crude, but safe. Iubyte *outbuffer = iAlloc((width*height*bpp)*2); // Save TGA file to buffer itga.save(outbuffer, itga.imageSize()*2); // Now we can delete memory buffer iDelete(data);
..as well as streams:
#include <imagen/iImage.h> using namespace imagen; // Open a new file stream for reading iFileStream instream("input.bmp", iRead); // Create an iImage object and load image from stream iImage img; img.load(&instream); // Open a file stream for writing iFileStream outstream("output.jpg", iWrite); // Save image to stream img.save(&outstream, iTypeJPEG);
You can also use any combination of these methods within a single image object.
API Documentation by Mark D. Procarione | Generated by |