#include
#include
void do_capture_screenshot (char *file, int sec)
{
gint x, y;
GdkScreen* cur_screen = NULL;
GdkWindow* window = NULL;
GdkPixbuf* pixbuf_screenshot = NULL;
GdkRectangle rect;
GdkRectangle screen_rect;
g_printf("ready to capture.....\r\n");
sleep(sec);
if (cur_screen == NULL)
cur_screen = gdk_screen_get_default ();
screen_rect.x = 0;
screen_rect.y = 0;
screen_rect.width = gdk_screen_get_width (cur_screen);
screen_rect.height = gdk_screen_get_height (cur_screen);
window = gdk_screen_get_root_window (cur_screen);
gdk_window_get_origin (window, &x, &y);
rect.x = x;
rect.y = y;
gdk_drawable_get_size (GDK_DRAWABLE (window), &rect.width,
&rect.height);
if (! gdk_rectangle_intersect (&rect, &screen_rect, &rect)) {
g_print("Capture failed!...\r\n");
return;
}
pixbuf_screenshot = gdk_pixbuf_get_from_drawable (NULL, window,
NULL,rect.x - x, rect.y - y, 0, 0,
rect.width, rect.height);
gdk_pixbuf_save (pixbuf_screenshot, file, "jpeg", NULL, "quality",
"100", NULL);
g_object_unref (pixbuf_screenshot);
g_print("Capture saved!!!\r\n");
return;
}
int main(int argc,char **argv)
{
char *file=argv[1];
do_capture_screenshot (file, 5);
}[/code]gcc -g -o pic pic.c `pkg-config --libs --cflags gtk+-2.0`编译成功
运行报错
(process:7155): GLib-GObject-CRITICAL **: /build/buildd/glib2.0-2.22.3/gobject/gtype.c:2458: initialization assertion failed, use IA__g_type_init() prior to this function
(process:7155): GLib-CRITICAL **: g_once_init_leave: assertion `initialization_value != 0' failed
(process:7155): Gdk-CRITICAL **: gdk_screen_get_width: assertion `GDK_IS_SCREEN (screen)' failed
求解决办法
hml1006 于 2011-04-18 12:08:44发表:
zenmemeirenhui