mr-edd.co.uk :: horsing around with the C++ programming language

pngxx

pngxx is a C++ library for reading and writing PNG images that wraps the libpng C library.

It allows you to read and write images to any source or sink, which may be described by standard C++ iterators or streams. By using the provided iterator adaptors, you can use your own image container objects.

Recent activity

Code

Clone the repository using mercurial:

> hg clone http://bitbucket.org/edd/pngxx

Or get a zip file of the code.

Quick start

To load an image from a file:

#include <pngxx/read.hpp>

std::vector<unsigned char> raster;
imagexx::raster_details d = 
    pngxx::read_image("image.png", back_inserter(raster));

std::size_t width = d.width();
std::size_t height = d.height();
imagexx::pixel_format f = d.type();
double width_mm = d.width_mm(); // in millimeters
double height_mm = d.height_mm(); // in millimeters

To save an image to a file:

#include <pngxx/write.hpp>

imagexx::raster_details d(imagexx::rgba, width, height);
pngxx::write_image(d, "image.png", raster.begin(), raster.end());

These examples show reading and writing with a std::vector used for raster storage. You can use the provided iterator adaptors to have the library integrate with your own image container objects.

You can read and write to memory, or any location that can be exposed via a standard C++ a stream or via iterators.

Further reading

Comments

(optional)
(optional)
(required, hint)

Links can be added like [this one -> http://www.mr-edd.co.uk], to my homepage.
Phrases and blocks of code can be enclosed in {{{triple braces}}}.
Any HTML markup will be escaped.