14.7 PNG

The PNG format will accept either greyscale or RGB pixmaps, with or without alpha. As a special case, alpha only pixmaps are accepted and written as greyscale.

/* 
   fz_save_pixmap_as_png: Save a pixmap as a PNG image file. 
*/ 
void fz_save_pixmap_as_png(fz_context *ctx, fz_pixmap *pixmap, const char *filename); 
 
/* 
   Write a pixmap to an output stream in PNG format. 
*/ 
void fz_write_pixmap_as_png(fz_context *ctx, fz_output *out, const fz_pixmap *pixmap); 
 
/* 
   fz_new_png_band_writer: Obtain a fz_band_writer instance 
   for producing PNG output. 
*/ 
fz_band_writer *fz_new_png_band_writer(fz_context *ctx, fz_output *out);

Because PNG is such a useful and widely used format, we have another couple of functions. These take either a fz_image or a fz_pixmap and produce a fz_buffer containing a PNG encoded version. This is very useful when converting between document formats as we can frequently use a PNG version of an image as a replacement for other image formats that may not be supported.

/* 
   Create a new buffer containing the image/pixmap in PNG format. 
*/ 
fz_buffer *fz_new_buffer_from_image_as_png(fz_context *ctx, fz_image *image); 
fz_buffer *fz_new_buffer_from_pixmap_as_png(fz_context *ctx, fz_pixmap *pixmap);