Re: Using gdk_pixbuf_xlib_get_from_drawable()
- From: Димитров Вячеслав <bordimida mail ru>
- To: gtk-list gnome org
- Subject: Re: Using gdk_pixbuf_xlib_get_from_drawable()
- Date: Sat, 18 Oct 2008 04:55:58 +0400
Hi.
In old mail list (2007 year), I saw this problem:
Hello,
I have a problem using the function from the subject. I think I'm
just missing something about how the function works. Here is the
code (it's just a short program to test the function):
### BEGIN CODE ###
#include <gdk-pixbuf-xlib/gdk-pixbuf-xlib.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
static void
screenshot (GtkWidget *widget)
{
GdkPixbuf *image;
XWindowAttributes wa;
Window win;
win = GDK_WINDOW_XID (widget->window);
XGetWindowAttributes (GDK_DISPLAY(), win, &wa);
image = gdk_pixbuf_xlib_get_from_drawable (NULL,
win, 0, NULL,
0, 0, 0, 0,
wa.width, wa.height);
gdk_pixbuf_save (image, "test.png", "png", NULL, NULL);
}
intmain (int argc, char *argv[])
{
GtkWidget *window, *button;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
button = gtk_button_new_with_label ("Hello");
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (screenshot), NULL);
gtk_container_add (GTK_CONTAINER (window), button);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
### END CODE ###
It is crashing in the .._from_drawable() function as you can
see here:
Program received signal SIGSEGV, Segmentation fault.
0x004943dd in XGetWindowAttributes () from /usr/lib/libX11.so.6
(gdb) where
#0 0x004943dd in XGetWindowAttributes () from /usr/lib/libX11.so.6
#1 0x004651d9 in gdk_pixbuf_xlib_get_from_drawable ()
from /usr/lib/libgdk_pixbuf_xlib-2.0.so.0
#2 0x080488ab in screenshot (widget=0x9caed68) at test.c:36
I am compiling with:
gcc -Wall -g test.c -o exe `pkg-config --cflags --libs gtk+-2.0
gdk-pixbuf-xlib-2.0`
Thank you for any help you can give me! - Andrew
A work code is representing so:
static void
screenshot (GtkWidget *widget)
{
GdkPixbuf *image;
XWindowAttributes wa;
Window win;
/*Must init display.*/
gdk_pixbuf_xlib_init(GDK_DISPLAY(), 0);
win = GDK_WINDOW_XID (widget->window);
XGetWindowAttributes (GDK_DISPLAY(), win, &wa);
image = gdk_pixbuf_xlib_get_from_drawable (NULL,
win, 0, NULL,
0, 0, 0, 0,
wa.width, wa.height);
gdk_pixbuf_save (image, "test.png", "png", NULL, NULL);
}
With regards Dimitrov Vyacheslav.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]