2000-01-06 01:08:10 +00:00
|
|
|
<!-- ##### SECTION Title ##### -->
|
|
|
|
Scaling
|
|
|
|
|
|
|
|
<!-- ##### SECTION Short_Description ##### -->
|
|
|
|
Scaling pixbufs and scaling and compositing pixbufs
|
|
|
|
|
|
|
|
<!-- ##### SECTION Long_Description ##### -->
|
2000-04-13 01:18:41 +00:00
|
|
|
<para>
|
2000-10-09 17:22:20 +00:00
|
|
|
The &gdk-pixbuf; contains functions to scale pixbufs, to scale
|
|
|
|
pixbufs and composite against an existing image, and to scale
|
|
|
|
pixbufs and composite against a solid color or checkerboard.
|
|
|
|
Compositing a checkerboard is a common way to show an image with
|
|
|
|
an alpha channel in image-viewing and editing software.
|
2000-04-13 01:18:41 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Since the full-featured functions (gdk_pixbuf_scale(),
|
|
|
|
gdk_pixbuf_composite(), and gdk_pixbuf_composite_color()) are
|
|
|
|
rather complex to use and have many arguments, two simple
|
|
|
|
convenience functions are provided, gdk_pixbuf_scale_simple() and
|
|
|
|
gdk_pixbuf_composite_color_simple() which create a new pixbuf of a
|
|
|
|
given size, scale an original image to fit, and then return the
|
|
|
|
new pixmap.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The following example demonstrates handling an expose event by
|
|
|
|
rendering the appropriate area of a source image (which is scaled
|
|
|
|
to fit the widget) onto the widget's window. The source image is
|
|
|
|
rendered against a checkerboard, which provides a visual
|
|
|
|
representation of the alpha channel if the image has one. If the
|
|
|
|
image doesn't have an alpha channel, calling
|
|
|
|
gdk_pixbuf_composite_color() function has exactly the same effect
|
|
|
|
as calling gdk_pixbuf_scale().
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<programlisting>
|
2000-01-06 01:08:10 +00:00
|
|
|
gboolean
|
|
|
|
expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
|
|
|
|
{
|
|
|
|
GdkPixbuf *dest;
|
|
|
|
|
|
|
|
gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
|
|
|
|
|
2000-04-13 01:18:41 +00:00
|
|
|
dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, event->area.width, event->area.height);
|
2000-01-06 01:08:10 +00:00
|
|
|
|
|
|
|
gdk_pixbuf_composite_color (pixbuf, dest,
|
|
|
|
0, 0, event->area.width, event->area.height,
|
|
|
|
-event->area.x, -event->area.y,
|
2000-04-13 01:18:41 +00:00
|
|
|
(double) widget->allocation.width / gdk_pixbuf_get_width (pixbuf),
|
|
|
|
(double) widget->allocation.height / gdk_pixbuf_get_height (pixbuf),
|
|
|
|
GDK_INTERP_BILINEAR, 255,
|
|
|
|
event->area.x, event->area.y, 16, 0xaaaaaa, 0x555555);
|
2000-01-06 01:08:10 +00:00
|
|
|
|
|
|
|
gdk_pixbuf_render_to_drawable (dest, widget->window, widget->style->fg_gc[GTK_STATE_NORMAL],
|
|
|
|
0, 0, event->area.x, event->area.y,
|
|
|
|
event->area.width, event->area.height,
|
|
|
|
GDK_RGB_DITHER_NORMAL, event->area.x, event->area.y);
|
|
|
|
|
|
|
|
gdk_pixbuf_unref (dest);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2000-04-13 01:18:41 +00:00
|
|
|
</programlisting>
|
2000-01-06 01:08:10 +00:00
|
|
|
|
|
|
|
<!-- ##### SECTION See_Also ##### -->
|
2000-04-13 01:18:41 +00:00
|
|
|
<para>
|
|
|
|
GdkRGB
|
|
|
|
</para>
|
|
|
|
|