2011-12-03 60 views
1

我有以下程序不能正常工作如何採取截圖在VALA

注意:在使用GTK的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");   
} 
+0

我所做的,只是需要做Gtk.Window的實例,並提取get_screen Gdk.Screen代替。 – rChavz

回答

4

編制;

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