[Gtk-sharp-list] grabbing a screenshot from C#? (Correct code implementation)

David Huseby dave at linuxprogrammer.org
Fri Apr 6 14:04:27 EDT 2007


Here's how to do it exactly.  I have tested this and it works:

// holder variables
int width = 0;
int height = 0;

// get the root window
// NOTE: if you have multiple monitors, this may not grab the correct root
window
// or it may grab the entire desktop if it is stretched over multiple
screens (a la xinerama)
// there are ways to enumerate the screens and pick the one you want...
Gdk.Window root = Gdk.Global.DefaultRootWindow;

// get its width and height
root.GetSize(out width, out height);

// create a new pixbuf from the root window
Gdk.Pixbuf screenshot = Gdk.Pixbuf.FromDrawable(root, root.Colormap, 0, 0,
0, 0, width, height);

// save it
screenshot.Save("~/screenshot.png", "png");

// or do whatever you want with it...


Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20070406/1d23efd1/attachment.html 


More information about the Gtk-sharp-list mailing list