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
- The pngxx wiki
- Loading PNG images in to a custom image container object
- Saving PNG images from a custom image container object
Comments
All original content copyright© Edd Dawson.
All source code appearing on this website that was written by Edd Dawson is made available under the terms of the Boost software license version 1.0 unless otherwise stated or implied by the license associated with the work from which the code is derived.
