1

我有以下程序不起作用

注意:在 Windows 7 上编译。

Gdk.Screen screen = Gdk.Screen.get_default ();      
Gdk.Window rootWin2 = screen.get_active_window ();
int width, height;
rootWin2.get_size (out width, out height);
Gdk.Colormap? colormap= rootWin2.get_colormap (); 
Gdk.Pixbuf? dest = new Gdk.Pixbuf (Gdk.Colorspace.RGB, false, 8, width, height);
Gdk.pixbuf_get_from_drawable (dest, rootWin2, colormap, 0, 0, 0, 0, width, height);     

try {
    dest.save("screenShoot2.jpg", "jpeg");
} catch (Error e) {
    stdout.printf("\n eerorrr   " + e.message + "\n");           
}
4

1 回答 1

4

使用 Gtk;

int main (string[] args) {
    Gtk.init (ref args);

    int  width, height;

    Gdk.Window win = Gdk.get_default_root_window();

    width = win.get_width();
    height = win.get_height();

    Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height);

    screenshot.save("screenshot.png","png");
    return 0;
}

//  valac --pkg gtk+-3.0 --pkg gdk-3.0  screenshot.vala 
于 2012-04-17T04:51:14.380 回答