相关疑难解决方法(0)

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

我正在尝试捕获屏幕图像以用于截屏.因此我需要一个快速的解决方案,并且不能依赖shell程序,如import或xwd.

这是我到目前为止编写的代码,但是它失败并且给了我一个垃圾图像,它似乎只是显示了奇怪颜色的几个图像的片段.

http://s9.postimage.org/dqnkgkwr1/blah.png

关于我做错了什么的任何想法?

#include <X11/Xlib.h>
#include <X11/X.h>

#include <cstdio>
#include <CImg.h>
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];

   unsigned long red_mask = image->red_mask;
   unsigned long green_mask = image->green_mask;
   unsigned long blue_mask = image->blue_mask;

   for (int x = 0; x < …
Run Code Online (Sandbox Code Playgroud)

c c++ screenshot xlib cimg

23
推荐指数
2
解决办法
1万
查看次数

标签 统计

c ×1

c++ ×1

cimg ×1

screenshot ×1

xlib ×1