1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 Scaling pixbufs and scaling and compositing pixbufs
7 <!-- ##### SECTION Long_Description ##### -->
9 gdk-pixbuf contains functions to scale pixbufs, to scale pixbufs and
10 composite against an existing image, and to scale pixbufs and
11 composite against a solid color or checkerboard. (Compositing a
12 checkerboard is a common way to show an image with an alpha-channel in
13 image-viewing and editing software.)
16 Since the full-featured functions (gdk_pixbuf_scale(),
17 gdk_pixbuf_composite(), and gdk_pixbuf_composite_color()) are
18 rather complex to use and have many arguments, two simple
19 convenience functions are provided, gdk_pixbuf_scale_simple()
20 and gdk_pixbuf_composite_color_simple() which create a
21 new pixbuf of a given size, scale an original image to fit,
22 and then return the new pixmap.
26 The following example demonstrates handling an expose event by
27 rendering the appropriate area of a source image (which is scaled to
28 fit the widget) onto the widget's window. The source image is
29 rendered against a checkerboard, which provides a visual
30 representation of the alpha channel if the image has one. If the image
31 doesn't have an alpha channel, calling gdk_pixbuf_composite_color()
32 function has exactly the same effect as calling gdk_pixbuf_scale().
37 expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
41 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
43 dest = gdk_pixbuf_new (ART_PIX_RGB, FALSE, 8, event->area.width, event->area.height);
45 gdk_pixbuf_composite_color (pixbuf, dest,
46 0, 0, event->area.width, event->area.height,
47 -event->area.x, -event->area.y,
48 (double) widget->allocation.width / pixbuf->art_pixbuf->width,
49 (double) widget->allocation.height / pixbuf->art_pixbuf->height,
51 event->area.x, event->area.y, 16, 0xaaaaaa, 0x555555);
53 gdk_pixbuf_render_to_drawable (dest, widget->window, widget->style->fg_gc[GTK_STATE_NORMAL],
54 0, 0, event->area.x, event->area.y,
55 event->area.width, event->area.height,
56 GDK_RGB_DITHER_NORMAL, event->area.x, event->area.y);
58 gdk_pixbuf_unref (dest);
64 <!-- ##### SECTION See_Also ##### -->
69 <!-- ##### FUNCTION gdk_pixbuf_scale ##### -->
87 <!-- ##### FUNCTION gdk_pixbuf_composite ##### -->
106 <!-- ##### FUNCTION gdk_pixbuf_composite_color ##### -->
130 <!-- ##### FUNCTION gdk_pixbuf_scale_simple ##### -->
142 <!-- ##### FUNCTION gdk_pixbuf_composite_color_simple ##### -->
160 sgml-parent-document: ("../gdk-pixbuf.sgml" "book" "refsect2" "")