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 this (Take a screenshot via a python script. [Linux]); I just need to figure out how to do that in C.
You don't need to write a tool as long as you use the reference compositor Weston for Wayland . It has this feature built in. You can use Super + S to take a screenshot and Super + R to record a video in *.
Shift + PrtScn - Take a screenshot of a section of the screen. Alt + PrtScn - Take a screenshot of the active window to users' home 'Pictures' directory. Ctrl + PrtScn - Take a screenshot of the whole screen to the clipboard.
Press the Windows key + PrintScreen on your keyboard (or, PrtSc). Screenshots are automatically saved to Pictures/Screenshots in your user directory (C:/Users/%username%/Pictures/Screenshots by default).
The protocol is simple and based on X window properties and X client messages: The gtk module sets the GTK_VECTOR_SCREENSHOT property for each top-level X window to some arbitrary value (currently "supported").
This examples show how to take screenshot using C#. This method shows you a simple method of capturing screenshots using C# and .NET 2.0 ( CopyFromScreen () method. ) //Create a new bitmap. // Create a graphics object from the bitmap. // Take the screenshot from the upper left corner to the right bottom corner.
This method shows you a simple method of capturing screenshots using C# and .NET 2.0 ( CopyFromScreen () method. ) //Create a new bitmap. // Create a graphics object from the bitmap. // Take the screenshot from the upper left corner to the right bottom corner. This method uses GDI in C#.NET to draw the primary screen onto a bitmap.
On Windows 10 and 8, press Windows Key + PrtScn to capture the entire screen. On Windows 7 and earlier, press PrtScn. To capture only the active window, press Alt + PrtScn. To capture specific parts of the screen, use the Windows Snipping Tool or Snip & Sketch. This article explains how to take screenshots on a Windows PC.
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!
9 years passed and as mentioned above API is removed.
As far as I understand, currently the bare minimum to do this at Linux is:
GdkWindow * root;
GdkPixbuf * screenshot;
gint x, y, width, height;
root = gdk_get_default_root_window ();
gdk_window_get_geometry (root, &x, &y, &width, &height);
screenshot = gdk_pixbuf_get_from_window (root, x, y, width, height);
// gdk_pixbuf_save...
This is very slightly tested and may fail. Further reading is in gnome-screenshooter repo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With