]> Pileus Git - ~andy/gtk/blob - docs/reference/gdk-pixbuf/tmpl/scaling.sgml
urg, removed implementation of gtk_marshal_VOID__INT_INT_INT_INT. if
[~andy/gtk] / docs / reference / gdk-pixbuf / tmpl / scaling.sgml
1 <!-- ##### SECTION Title ##### -->
2 Scaling
3
4 <!-- ##### SECTION Short_Description ##### -->
5 Scaling pixbufs and scaling and compositing pixbufs
6
7 <!-- ##### SECTION Long_Description ##### -->
8   <para>
9     The &gdk-pixbuf; contains functions to scale pixbufs, to scale
10     pixbufs and composite against an existing image, and to scale
11     pixbufs and composite against a solid color or checkerboard.
12     Compositing a checkerboard is a common way to show an image with
13     an alpha channel in image-viewing and editing software.
14   </para>
15
16   <para>
17     Since the full-featured functions (gdk_pixbuf_scale(),
18     gdk_pixbuf_composite(), and gdk_pixbuf_composite_color()) are
19     rather complex to use and have many arguments, two simple
20     convenience functions are provided, gdk_pixbuf_scale_simple() and
21     gdk_pixbuf_composite_color_simple() which create a new pixbuf of a
22     given size, scale an original image to fit, and then return the
23     new pixmap.
24   </para>
25
26   <para>
27     The following example demonstrates handling an expose event by
28     rendering the appropriate area of a source image (which is scaled
29     to fit the widget) onto the widget's window.  The source image is
30     rendered against a checkerboard, which provides a visual
31     representation of the alpha channel if the image has one. If the
32     image doesn't have an alpha channel, calling
33     gdk_pixbuf_composite_color() function has exactly the same effect
34     as calling gdk_pixbuf_scale().
35   </para>
36
37   <programlisting>
38 gboolean
39 expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
40 {
41   GdkPixbuf *dest;
42
43   gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
44   
45   dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, event->area.width, event->area.height);
46
47   gdk_pixbuf_composite_color (pixbuf, dest,
48                               0, 0, event->area.width, event->area.height,
49                               -event->area.x, -event->area.y,
50                               (double) widget->allocation.width / gdk_pixbuf_get_width (pixbuf),
51                               (double) widget->allocation.height / gdk_pixbuf_get_height (pixbuf),
52                               GDK_INTERP_BILINEAR, 255,
53                               event->area.x, event->area.y, 16, 0xaaaaaa, 0x555555);
54
55   gdk_pixbuf_render_to_drawable (dest, widget->window, widget->style->fg_gc[GTK_STATE_NORMAL],
56                                  0, 0, event->area.x, event->area.y,
57                                  event->area.width, event->area.height,
58                                  GDK_RGB_DITHER_NORMAL, event->area.x, event->area.y);
59   
60   gdk_pixbuf_unref (dest);
61   
62   return TRUE;
63 }
64   </programlisting>
65
66 <!-- ##### SECTION See_Also ##### -->
67   <para>
68     GdkRGB
69   </para>
70