Next: , Previous: PDF Surfaces, Up: Top


18 PNG Support

Reading and writing PNG images

18.1 Overview

The PNG functions allow reading PNG images into image surfaces, and writing any surface to a PNG file.

18.2 Usage

— Function: cairo-image-surface-create-from-png (filename <char>) ⇒  (ret <cairo-surface-t >)

Creates a new image surface and initializes the contents to the given PNG file.

filename
name of PNG file to load
ret
a new <cairo-surface-t> initialized with the contents of the PNG file, or a "nil" surface if any error occurred. 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_FILE_NOT_FOUND’‘CAI RO_STATUS_READ_ERROR’ Alternatively, you can allow errors to propagate through the drawing operations and check the status on the context upon completion using cairo-status.
— Function: cairo-surface-write-to-png (surface <cairo-surface-t>) (filename <char>) ⇒  (ret <cairo-status-t>)

Writes the contents of surface to a new file filename as a PNG image.

surface
a <cairo-surface-t> with pixel contents
filename
the name of a file to write to
ret
CAIRO_STATUS_SUCCESS’ if the PNG file was written successfully. Otherwise, ‘CAIRO_STATUS_NO_MEMORY’ if memory could not be allocated for the operation or ‘CAIRO_STATUS_SURFACE_TYPE_MISMATCH’ if the surface does not have pixel contents, or ‘CAIRO_STATUS_WRITE_ERROR’ if an I/O error occurs while attempting to write the file.