Tag: screenshot

如何使用xlib正确截取屏幕截图?

我正在尝试捕获屏幕图像以用于截屏。 因此我需要一个快速的解决方案,并且不能依赖shell程序,如import或xwd。 这是我到目前为止编写的代码,但是它失败并且给了我一个垃圾图像,它似乎只是显示了几个奇怪颜色的图像片段被拼凑在一起。 http://sofzh.miximages.com/c%2B%2B/blah.png 关于我做错的任何想法? #include #include #include #include using namespace cimg_library; int main() { Display *display = XOpenDisplay(NULL); Window root = DefaultRootWindow(display); XWindowAttributes gwa; XGetWindowAttributes(display, root, &gwa); int width = gwa.width; int height = gwa.height; XImage *image = XGetImage(display,root, 0,0 , width,height,AllPlanes, ZPixmap); unsigned char *array = new unsigned char[width * height * 3]; […]