Next: , Previous: Images, Up: Top


12 Pixbufs

Functions for rendering pixbufs on drawables

12.1 Overview

These functions allow to render pixbufs on drawables. Pixbufs are client-side images. For details on how to create and manipulate pixbufs, see the <gdk-pixbuf> API documentation.

12.2 Usage

— Function: gdk-pixbuf-render-threshold-alpha (self <gdk-pixbuf>) (bitmap <gdk-drawable>) (src_x int) (src_y int) (dest_x int) (dest_y int) (width int) (height int) (alpha_threshold int)
— Method: render-threshold-alpha

Takes the opacity values in a rectangular portion of a pixbuf and thresholds them to produce a bi-level alpha mask that can be used as a clipping mask for a drawable.

pixbuf
A pixbuf.
bitmap
Bitmap where the bilevel mask will be painted to.
src-x
Source X coordinate.
src-y
source Y coordinate.
dest-x
Destination X coordinate.
dest-y
Destination Y coordinate.
width
Width of region to threshold, or -1 to use pixbuf width
height
Height of region to threshold, or -1 to use pixbuf height
alpha-threshold
Opacity values below this will be painted as zero; all other values will be painted as one.
— Function: gdk-pixbuf-render-to-drawable (self <gdk-pixbuf>) (drawable <gdk-drawable>) (gc <gdk-gc>) (src_x int) (src_y int) (dest_x int) (dest_y int) (width int) (height int) (dither <gdk-rgb-dither>) (x_dither int) (y_dither int)
— Method: render-to-drawable

gdk_pixbuf_render_to_drawable’ has been deprecated since version 2.4 and should not be used in newly-written code. This function is obsolete. Use gdk-draw-pixbuf instead.

Renders a rectangular portion of a pixbuf to a drawable while using the specified GC. This is done using GdkRGB, so the specified drawable must have the GdkRGB visual and colormap. Note that this function will ignore the opacity information for images with an alpha channel; the GC must already have the clipping mask set if you want transparent regions to show through.

For an explanation of dither offsets, see the GdkRGB documentation. In brief, the dither offset is important when re-rendering partial regions of an image to a rendered version of the full image, or for when the offsets to a base position change, as in scrolling. The dither matrix has to be shifted for consistent visual results. If you do not have any of these cases, the dither offsets can be both zero.

pixbuf
A pixbuf.
drawable
Destination drawable.
gc
GC used for rendering.
src-x
Source X coordinate within pixbuf.
src-y
Source Y coordinate within pixbuf.
dest-x
Destination X coordinate within drawable.
dest-y
Destination Y coordinate within drawable.
width
Width of region to render, in pixels, or -1 to use pixbuf width
height
Height of region to render, in pixels, or -1 to use pixbuf height
dither
Dithering mode for GdkRGB.
x-dither
X offset for dither.
y-dither
Y offset for dither.
— Function: gdk-pixbuf-render-to-drawable-alpha (self <gdk-pixbuf>) (drawable <gdk-drawable>) (src_x int) (src_y int) (dest_x int) (dest_y int) (width int) (height int) (alpha_mode <gdk-pixbuf-alpha-mode>) (alpha_threshold int) (dither <gdk-rgb-dither>) (x_dither int) (y_dither int)
— Method: render-to-drawable-alpha

gdk_pixbuf_render_to_drawable_alpha’ has been deprecated since version 2.4 and should not be used in newly-written code. This function is obsolete. Use gdk-draw-pixbuf instead.

Renders a rectangular portion of a pixbuf to a drawable. The destination drawable must have a colormap. All windows have a colormap, however, pixmaps only have colormap by default if they were created with a non-‘#f’ window argument. Otherwise a colormap must be set on them with gdk_drawable_set_colormap.

On older X servers, rendering pixbufs with an alpha channel involves round trips to the X server, and may be somewhat slow.

pixbuf
A pixbuf.
drawable
Destination drawable.
src-x
Source X coordinate within pixbuf.
src-y
Source Y coordinates within pixbuf.
dest-x
Destination X coordinate within drawable.
dest-y
Destination Y coordinate within drawable.
width
Width of region to render, in pixels, or -1 to use pixbuf width.
height
Height of region to render, in pixels, or -1 to use pixbuf height.
alpha-mode
Ignored. Present for backwards compatibility.
alpha-threshold
Ignored. Present for backwards compatibility
dither
Dithering mode for GdkRGB.
x-dither
X offset for dither.
y-dither
Y offset for dither.
— Function: gdk-pixbuf-get-from-drawable (self <gdk-pixbuf>) (src <gdk-drawable>) (cmap <gdk-colormap>) (src_x int) (src_y int) (dest_x int) (dest_y int) (width int) (height int) ⇒  (ret <gdk-pixbuf>)
— Method: get-from-drawable

Transfers image data from a <gdk-drawable> and converts it to an RGB(A) representation inside a <gdk-pixbuf>. In other words, copies image data from a server-side drawable to a client-side RGB(A) buffer. This allows you to efficiently read individual pixels on the client side.

If the drawable src has no colormap (gdk-drawable-get-colormap returns ‘#f’), then a suitable colormap must be specified. Typically a <gdk-window> or a pixmap created by passing a <gdk-window> to gdk-pixmap-new will already have a colormap associated with it. If the drawable has a colormap, the cmap argument will be ignored. If the drawable is a bitmap (1 bit per pixel pixmap), then a colormap is not required; pixels with a value of 1 are assumed to be white, and pixels with a value of 0 are assumed to be black. For taking screenshots, gdk-colormap-get-system returns the correct colormap to use.

If the specified destination pixbuf dest is ‘#f’, then this function will create an RGB pixbuf with 8 bits per channel and no alpha, with the same size specified by the width and height arguments. In this case, the dest-x and dest-y arguments must be specified as 0. If the specified destination pixbuf is not ‘#f’ and it contains alpha information, then the filled pixels will be set to full opacity (alpha = 255).

If the specified drawable is a pixmap, then the requested source rectangle must be completely contained within the pixmap, otherwise the function will return ‘#f’. For pixmaps only (not for windows) passing -1 for width or height is allowed to mean the full width or height of the pixmap.

If the specified drawable is a window, and the window is off the screen, then there is no image data in the obscured/offscreen regions to be placed in the pixbuf. The contents of portions of the pixbuf corresponding to the offscreen region are undefined.

If the window you're obtaining data from is partially obscured by other windows, then the contents of the pixbuf areas corresponding to the obscured regions are undefined.

If the target drawable is not mapped (typically because it's iconified/minimized or not on the current workspace), then ‘#f’ will be returned.

If memory can't be allocated for the return value, ‘#f’ will be returned instead.

(In short, there are several ways this function can fail, and if it fails it returns ‘#f’; so check the return value.)

This function calls gdk-drawable-get-image internally and converts the resulting image to a <gdk-pixbuf>, so the documentation for gdk-drawable-get-image may also be relevant.

dest
Destination pixbuf, or ‘#f’ if a new pixbuf should be created.
src
Source drawable.
cmap
A colormap if src doesn't have one set.
src-x
Source X coordinate within drawable.
src-y
Source Y coordinate within drawable.
dest-x
Destination X coordinate in pixbuf, or 0 if dest is NULL.
dest-y
Destination Y coordinate in pixbuf, or 0 if dest is NULL.
width
Width in pixels of region to get.
height
Height in pixels of region to get.
ret
The same pixbuf as dest if it was non-‘#f’, or a newly-created pixbuf with a reference count of 1 if no destination pixbuf was specified, or ‘#f’ on error
— Function: gdk-pixbuf-get-from-image (self <gdk-pixbuf>) (src <gdk-image>) (cmap <gdk-colormap>) (src_x int) (src_y int) (dest_x int) (dest_y int) (width int) (height int) ⇒  (ret <gdk-pixbuf>)
— Method: get-from-image

Same as gdk-pixbuf-get-from-drawable but gets the pixbuf from an image.

dest
Destination pixbuf, or ‘#f’ if a new pixbuf should be created.
src
Source <gdk-image>.
cmap
A colormap, or ‘#f’ to use the one for src
src-x
Source X coordinate within drawable.
src-y
Source Y coordinate within drawable.
dest-x
Destination X coordinate in pixbuf, or 0 if dest is NULL.
dest-y
Destination Y coordinate in pixbuf, or 0 if dest is NULL.
width
Width in pixels of region to get.
height
Height in pixels of region to get.
ret
dest, newly-created pixbuf if dest was ‘#f’, ‘#f’ on error