Taking a screenshot with C\GTK

后端 未结 2 618
有刺的猬
有刺的猬 2020-12-28 11:05

I\'m trying to take a screenshot of the entire screen with C and GTK. I don\'t want to make a call to an external application for speed reasons. I\'ve found Python code for

2条回答
  •  甜味超标
    2020-12-28 11:38

    After looking at the GNOME-Screenshot code and a Python example, I came up with this:

    GdkPixbuf * get_screenshot(){
        GdkPixbuf *screenshot;
        GdkWindow *root_window;
        gint x_orig, y_orig;
        gint width, height;
        root_window = gdk_get_default_root_window ();
        gdk_drawable_get_size (root_window, &width, &height);      
        gdk_window_get_origin (root_window, &x_orig, &y_orig);
    
        screenshot = gdk_pixbuf_get_from_drawable (NULL, root_window, NULL,
                                               x_orig, y_orig, 0, 0, width, height);
        return screenshot;
    }
    

    Which seems to work perfectly. Thanks!

提交回复
热议问题