An important point about the colormap. If the source drawable does
not have a colormap, a compatible one needs to be provided. If you
are capturing contents of a window then GdkWindow::get_colormap()
method can be used.
1: <?php
2: // Here we create a pixmap, draw something on it, then convert it
3: // to a GdkPixbuf and scale and composite it over a checkerboard
4: // pattern.
5:
6: // $window is a GtkWindow we created previously
7: $window->realize();
8:
9: $pm = &new GdkPixmap($window->window, 300, 300);
10: $win = $window->window;
11: $cmap = $window->get_colormap();
12: $c = $cmap->alloc('orange');
13: $c1 = $cmap->alloc('white');
14: $c2 = $cmap->alloc('gray50');
15: $gc = $win->new_gc();
16: $gc->foreground = $c;
17: $gc->line_width = 3;
18: gdk::draw_rectangle($pm, $window->style->white_gc, true, 0, 0, 300, 300);
19: gdk::draw_line($pm, $gc, 0, 0, 300, 300);
20: gdk::draw_line($pm, $gc, 0, 300, 300, 0);
21: gdk::draw_arc($pm, $gc, true, 100, 100, 100, 100, 64 * 45, 64 * 90);
22: gdk::draw_arc($pm, $gc, true, 100, 100, 100, 100, 64 * 225, 64 * 90);
23:
24: $pixbuf = gdkpixbuf::get_from_drawable(null, $pm, $cmap,
25: 0, 0, 0, 0, 300, 300);
26: $pixbuf = $pixbuf->composite_color_simple(500, 200, GDK_INTERP_BILINEAR,
27: 200, 8, $c1->pixel, $c2->pixel);
28:
29: // Display pixbuf as before
30: ?>