You could use Boost GIL
If you have the raw image data (or can produce it in some way):
unsigned char r[width * height]; // red
unsigned char g[width * height]; // green
unsigned char b[width * height]; // blue
You can write a .png file in this way:
#include <boost/gil/extension/io/png_io.hpp>
boost::gil::rgb8c_planar_view_t view = boost::gil::planar_rgb_view(width, height, r, g, b, width);
boost::gil::png_write_view("out.png", view);
If the image also contains an alpha channel
unsigned char a[width * height];
then
#include <boost/gil/extension/io/png_io.hpp>
boost::gil::rgba8c_planar_view_t view = boost::gil::planar_rgba_view(width, height, r, g, b, a, width);
boost::gil::png_write_view("out.png", view);
Remember to link your program with -lpng
Also take a look at boost gil create image