4

現在、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);
}

-lX11 を使用してコードをコンパイルして実行すると、セグメンテーション エラーが発生し続けます。何か案は?

前もって感謝します!

4

2 に答える 2

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);
于 2012-04-23T17:03:00.917 に答える
1

dplNULLかどうかを確認する必要があります。

私の経験に基づいた推測では、IPが機能していないということです。ほとんどのディストリビューションでは、tcp ソケットを介した xserver へのアクセスが許可されていないため、それらを有効にする必要があると思います (nolisten で無効にされます)。

于 2012-04-23T17:06:10.323 に答える