You could try CImg. It uses C++ class templates to represent images, with T
meaning what each pixel would be stored as. It consists of only a single header CImg.h
. Great features of it include how modifier functions return the same class, meaning you can "pipe" them together and the support of external libraries.
The formats it natively supports are ascii, cpp, dlm, bmp, jpeg, png, pnm, pnk, pfm, rgb minc2, nifti, cimg, inr, exr, pandore, raw, off (for 3d), yuv (store multiple images into a video), and tiff. TIFF support needs to be enabled through #define cimg_use_tiff
. Other image formats could be saved with this library if ImageMagick or GraphicsMagick is installed.
Here is the reference for the namesake class. You can use fill
for a lot of pixels or draw_point
for a specific pixel.
// read image in any Format
CImg<unsigned char> my_image( "oldimage.gif"); //T=unsigned char, meaning R/G/B must be whole number
// read and write a pixel
my_image( column, row, 0 ) = 255;
my_image( column, row, 1 ) = 0;
my_image( column, row, 2 ) = 0;
// 0 for red, 1 for green, 2 for blue.
// just write a pixel
const unsigned char red[3] = { 255, 0, 0 };
my_image.draw_point( column, row, red );
// save image in supported formats
my_image.save( "newimage.tiff" );