Next: , Previous: File Loading, Up: Top


31 Image Data in Memory

Creating a pixbuf from image data that is already in memory.

31.1 Overview

The most basic way to create a pixbuf is to wrap an existing pixel buffer with a <gdk-pixbuf> 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 <gdk-pixbuf> is finalized by the reference counting functions If you have a chunk of static data compiled into your application, you can pass in ‘#f’ 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 g-object-ref on the old pixbuf; the copy function will actually duplicate the pixel data in memory and create a new <gdk-pixbuf> structure for it.

31.2 Usage

— Function: gdk-pixbuf-new (colorspace <gdk-colorspace>) (has_alpha bool) (bits_per_sample int) (width int) (height int) ⇒  (ret <gdk-pixbuf>)

Creates a new <gdk-pixbuf> 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.

colorspace
Color space for image
has-alpha
Whether the image should have transparency information
bits-per-sample
Number of bits per color sample
width
Width of image in pixels, must be > 0
height
Height of image in pixels, must be > 0
ret
A newly-created <gdk-pixbuf> with a reference count of 1, or ‘#f’ if not enough memory could be allocated for the image buffer.
— Function: gdk-pixbuf-new-subpixbuf (self <gdk-pixbuf>) (src_x int) (src_y int) (width int) (height int) ⇒  (ret <gdk-pixbuf>)
— Method: new-subpixbuf

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.

src-pixbuf
a <gdk-pixbuf>
src-x
X coord in src-pixbuf
src-y
Y coord in src-pixbuf
width
width of region in src-pixbuf
height
height of region in src-pixbuf
ret
a new pixbuf