Hi,


On Thu, 27 Apr 2006, Kalle Vahlman wrote:

On 4/27/06, sadhees kumar <[EMAIL PROTECTED]> wrote:
                        In short I would like to know how to take a
GtkWidget in to a pixbuf.

I tried the command
gdk_pixbuf_get_from_drawable(),
but in vain. It would be very helpfull if anybody suggest me with some
example code.

I think that should work when you give the widgets GdkWindow (which is
a GdkDrawable) as the parameter, which is accessible as
widget->window.

So something like

pixbuf = gdk_pixbuf_get_from_drawable (NULL, widget->window, NULL,
widget->allocation.x, widget->allocation.y, 0, 0,
widget->allocation.width, widget->allocation.height);

should work as you want. The use of allocation for coordinates is in
case the widget  has not got a window of it's own (in that case
widget->window points to its parent widgets window).

But please not that if your widget has any child widgets
with windows of their own, this won't work. If this
is the case, you'll have to use the root window as argument
to gdk_pixbuf_get_from_drawable.

Both Kalle's solution and the rootwindow thing has the
limitation that the widget must be visible on the screen.

One guru told me that Gnome theme seletor has some trick
where you temporary replace widget->window pointer with a pointer to a pixbuf and then send a fake expoce event
to the widget. This forces the widget to draw itself directly
to the pixbuf even if not visible on the screen.

This won't work either when there is child widgets with
windows of their own around, but if you can quarantee
that this is not the case, I would choose this approach.

Br,
Sampo
_______________________________________________
gtk-devel-list mailing list
gtk-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-devel-list

Reply via email to