Taking screenshot with libx11

江枫思渺然 提交于 2019-12-18 17:12:32

问题


I'm currently trying to take a screenshot using libx11

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>

int main(void) {
XImage* pic;
Display* dpl;
unsigned int buffer_size;

dpl = XOpenDisplay("127.0.0.1:0.0");

pic = XGetImage(dpl, RootWindow(dpl, DefaultScreen(dpl)), 10, 10, 201, 201,
        AllPlanes, ZPixmap);
}

if I compile the code using -lX11 and run it I keep getting a segmentation fault. Any ideas?

Thanks in advance!


回答1:


The X11 server does not usually listen on TCP/IP localhost, but on a Unix socket. At any rate, you should not hard-code the address of the X11 server. Try this:

dpl = XOpenDisplay(NULL);
assert(dpl);



回答2:


You should check if dpl is NULL.

My educated guess, is that the ip is not working. Most distribution do NOT allow access to the xserver via tcp sockets, so I guess you have to enable them (they are disabled with nolisten).



来源:https://stackoverflow.com/questions/10284858/taking-screenshot-with-libx11

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!