Next: , Previous: , Up: Top   [Index]


16 Image Surfaces

Rendering to memory buffers

16.1 Overview

Image surfaces provide the ability to render to memory buffers either allocated by cairo or by the calling code. The supported image formats are those defined in <cairo-format-t>.

16.2 Usage

Function: cairo-format-stride-for-width (format <cairo-format-t>) (width <int>) ⇒  (ret <int>)

This function provides a stride value that will respect all alignment requirements of the accelerated image-rendering code within cairo. Typical usage will be of the form:


int stride;
unsigned char *data;
cairo_surface_t *surface;

stride = cairo_format_stride_for_width (format, width);
data = malloc (stride * height);
surface = cairo_image_surface_create_for_data (data, format,
					  width, height,
					  stride);
format

A <cairo-format-t> value

width

The desired width of an image surface to be created.

ret

the appropriate stride to use given the desired format and width, or -1 if either the format is invalid or the width too large.

Since 1.6

Function: cairo-image-surface-create (format <cairo-format-t>) (width <int>) (height <int>) ⇒  (ret <cairo-surface-t >)

Creates an image surface of the specified format and dimensions. Initially the surface contents are all 0. (Specifically, within each pixel, each color or alpha channel belonging to format will be 0. The contents of bits within a pixel, but not belonging to the given format are undefined).

format

format of pixels in the surface to create

width

width of the surface, in pixels

height

height of the surface, in pixels

ret

a pointer to the newly created surface. The caller owns the surface and should call cairo-surface-destroy when done with it. This function always returns a valid pointer, but it will return a pointer to a "nil" surface if an error such as out of memory occurs. You can use cairo-surface-status to check for this.

Function: cairo-image-surface-get-format (surface <cairo-surface-t>) ⇒  (ret <cairo-format-t>)

Get the format of the surface.

surface

a <cairo-image-surface-t>

ret

the format of the surface

Since 1.2

Function: cairo-image-surface-get-width (surface <cairo-surface-t>) ⇒  (ret <int>)

Get the width of the image surface in pixels.

surface

a <cairo-image-surface-t>

ret

the width of the surface in pixels.

Function: cairo-image-surface-get-height (surface <cairo-surface-t>) ⇒  (ret <int>)

Get the height of the image surface in pixels.

surface

a <cairo-image-surface-t>

ret

the height of the surface in pixels.

Function: cairo-image-surface-get-stride (surface <cairo-surface-t>) ⇒  (ret <int>)

Get the stride of the image surface in bytes

surface

a <cairo-image-surface-t>

ret

the stride of the image surface in bytes (or 0 if surface is not an image surface). The stride is the distance in bytes from the beginning of one row of the image data to the beginning of the next row.

Since 1.2


Next: , Previous: , Up: Top   [Index]