我找到了这个code http://ted.mielczarek.org/code/screenshot/在 Ted Mielczarek 网站上截取屏幕截图。
/*
* gdk-screenshot.cpp: Save a screenshot of the root window in .png format.
* If a filename is specified as the first argument on the commandline,
* then the image will be saved to that filename. Otherwise, the image will
* be saved as "screenshot.png" in the current working directory.
*
* Compile with:
* g++ -o gdk-screenshot gdk-screenshot.cpp `pkg-config --cflags --libs gdk-x11-2.0`
*/
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
int main(int argc, char** argv)
{
gdk_init(&argc, &argv);
GdkWindow* window = window = gdk_get_default_root_window ();
GdkPixbuf* screenshot = gdk_pixbuf_get_from_drawable (NULL, window, NULL,
0, 0, 0, 0,
gdk_screen_width(),
gdk_screen_height());
GError* error = NULL;
const char* filename = (argc > 1) ? argv[1] : "screenshot.png";
return TRUE == gdk_pixbuf_save (screenshot, filename, "png",
&error, NULL);
}
I compiled it as described and it appears to work, in that it produces an image with the correct dimensions, but the screenshot is entirely black.
这似乎是一个common https://bugzilla.redhat.com/show_bug.cgi?id=1398556 issue https://bugs.freedesktop.org/show_bug.cgi?id=98672在运行 Wayland 的系统上(我正在使用 Wayland 运行 Archlinux),所以我的问题是:
需要对此代码进行哪些修改才能使其在 Wayland(和 X)上生成正确的屏幕截图?