Name
Image Data in Memory -- Creating a pixbuf from image data that is already in memory.
Synopsis
#include <gdk-pixbuf/gdk-pixbuf.h>
GdkPixbuf* gdk_pixbuf_new (GdkColorspace colorspace,
gboolean has_alpha,
int bits_per_sample,
int width,
int height);
GdkPixbuf* gdk_pixbuf_new_from_data (const guchar *data,
GdkColorspace colorspace,
gboolean has_alpha,
int bits_per_sample,
int width,
int height,
int rowstride,
GdkPixbufDestroyNotify destroy_fn,
gpointer destroy_fn_data);
GdkPixbuf* gdk_pixbuf_new_from_xpm_data (const char **data);
GdkPixbuf* gdk_pixbuf_new_from_inline (const guchar *inline_pixbuf,
gboolean copy_pixels,
int length,
GError **error);
GdkPixbuf* gdk_pixbuf_new_subpixbuf (GdkPixbuf *src_pixbuf,
int src_x,
int src_y,
int width,
int height);
GdkPixbuf* gdk_pixbuf_copy (const GdkPixbuf *pixbuf); |
Description
The most basic way to create a pixbuf is to wrap an existing pixel
buffer with a GdkPixbuf structure. You can use the
gdk_pixbuf_new_from_data() function to do this You need to specify
the destroy notification function that will be called when the
data buffer needs to be freed; this will happen when a GdkPixbuf
is finalized by the reference counting functions If you have a
chunk of static data compiled into your application, you can pass
in NULL as the destroy notification function so that the data
will not be freed.
The gdk_pixbuf_new() function can be used as a convenience to
create a pixbuf with an empty buffer. This is equivalent to
allocating a data buffer using malloc() and then wrapping it with
gdk_pixbuf_new_from_data(). The gdk_pixbuf_new() function will
compute an optimal rowstride so that rendering can be performed
with an efficient algorithm.
As a special case, you can use the gdk_pixbuf_new_from_xpm_data()
function to create a pixbuf from inline XPM image data.
You can also copy an existing pixbuf with the gdk_pixbuf_copy()
function. This is not the same as just doing a gdk_pixbuf_ref()
on the old pixbuf; the copy function will actually duplicate the
pixel data in memory and create a new GdkPixbuf structure for it.
Details
gdk_pixbuf_new ()
Creates a new GdkPixbuf structure and allocates a buffer for it. The buffer
has an optimal rowstride. Note that the buffer is not cleared; you will have
to fill it completely yourself.
gdk_pixbuf_new_from_data ()
Creates a new GdkPixbuf out of in-memory image data. Currently only RGB
images with 8 bits per sample are supported.
gdk_pixbuf_new_from_xpm_data ()
GdkPixbuf* gdk_pixbuf_new_from_xpm_data (const char **data); |
Creates a new pixbuf by parsing XPM data in memory. This data is commonly
the result of including an XPM file into a program's C source.
gdk_pixbuf_new_from_inline ()
Create a GdkPixbuf from a custom format invented to store pixbuf
data in C program code. This library comes with a program called
"make-inline-pixbuf" that can write out a variable definition
containing an inlined pixbuf. This is useful if you want to ship a
program with images, but don't want to depend on any external
files.
The inline data format contains the pixels in GdkPixbuf's native
format. Since the inline pixbuf is read-only static data, you
don't need to copy it unless you intend to write to it.
If you create a pixbuf from const inline data compiled into your
program, it's probably safe to ignore errors, since things will
always succeed. For non-const inline data, you could get out of
memory. For untrusted inline data located at runtime, you could
have corrupt inline data in addition.
gdk_pixbuf_new_subpixbuf ()
GdkPixbuf* gdk_pixbuf_new_subpixbuf (GdkPixbuf *src_pixbuf,
int src_x,
int src_y,
int width,
int height); |
Creates a new pixbuf which represents a sub-region of
src_pixbuf. The new pixbuf shares its pixels with the
original pixbuf, so writing to one affects both.
The new pixbuf holds a reference to src_pixbuf, so
src_pixbuf will not be finalized until the new pixbuf
is finalized.
gdk_pixbuf_copy ()
Creates a new GdkPixbuf with a copy of the information in the specified
pixbuf.
See Also
gdk_pixbuf_finalize().