PNG Support
PNG Support — Reading and writing PNG images
|
|
Description
The PNG functions allow reading PNG images into image surfaces, and writing
any surface to a PNG file.
It is a toy API. It only offers very simple support for reading and
writing PNG files, which is sufficient for testing and
demonstration purposes. Applications which need more control over
the generated PNG file should access the pixel data directly, using
cairo_image_surface_get_data() or a backend-specific access
function, and process it with another library, e.g. gdk-pixbuf or
libpng.
Functions
cairo_image_surface_create_from_png ()
cairo_surface_t *
cairo_image_surface_create_from_png (const char *filename);
Creates a new image surface and initializes the contents to the
given PNG file.
Since: 1.0
cairo_read_func_t ()
cairo_status_t
(*cairo_read_func_t) (void *closure,
unsigned char *data,
unsigned int length);
cairo_read_func_t is the type of function which is called when a
backend needs to read data from an input stream. It is passed the
closure which was specified by the user at the time the read
function was registered, the buffer to read the data into and the
length of the data in bytes. The read function should return
CAIRO_STATUS_SUCCESS if all the data was successfully read,
CAIRO_STATUS_READ_ERROR otherwise.
Returns
the status code of the read operation
Since: 1.0
cairo_image_surface_create_from_png_stream ()
cairo_surface_t *
cairo_image_surface_create_from_png_stream
(cairo_read_func_t read_func,
void *closure);
Creates a new image surface from PNG data read incrementally
via the read_func
function.
Returns
a new cairo_surface_t initialized with the contents
of the PNG file or a "nil" surface if the data read is not a valid PNG image
or memory could not be allocated for the operation. A nil
surface can be checked for with cairo_surface_status(surface) which
may return one of the following values:
CAIRO_STATUS_NO_MEMORY
CAIRO_STATUS_READ_ERROR
CAIRO_STATUS_PNG_ERROR
Alternatively, you can allow errors to propagate through the drawing
operations and check the status on the context upon completion
using cairo_status().
Since: 1.0
cairo_surface_write_to_png ()
cairo_status_t
cairo_surface_write_to_png (cairo_surface_t *surface,
const char *filename);
Writes the contents of surface
to a new file filename
as a PNG
image.
Since: 1.0
cairo_write_func_t ()
cairo_status_t
(*cairo_write_func_t) (void *closure,
const unsigned char *data,
unsigned int length);
cairo_write_func_t is the type of function which is called when a
backend needs to write data to an output stream. It is passed the
closure which was specified by the user at the time the write
function was registered, the data to write and the length of the
data in bytes. The write function should return
CAIRO_STATUS_SUCCESS if all the data was successfully written,
CAIRO_STATUS_WRITE_ERROR otherwise.
Returns
the status code of the write operation
Since: 1.0
Types and Values
CAIRO_HAS_PNG_FUNCTIONS
#define CAIRO_HAS_PNG_FUNCTIONS 1
Defined if the PNG functions are available.
This macro can be used to conditionally compile code using the cairo
PNG functions.
Since: 1.0