我已经完成了一个 C 程序,它获取屏幕像素的 RGB 值(0-255),知道它的位置(x,y)。它适用于 Linux,但是当我尝试在 Visual Studio (Windows) 中编译它时,由于库 X11/Xlib.h、X11/Xutil.h、unistd.h 不存在而崩溃。
这是代码:
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
void getimage(XColor c, Display* d, int* rgb, int x, int y) {
XImage* image;
image = XGetImage(d, RootWindow(d, DefaultScreen(d)),
x, y, 1, 1, AllPlanes, XYPixmap);
c.pixel = XGetPixel(image, 0, 0);
XFree(image);
XQueryColor(d, DefaultColormap(d, DefaultScreen(d)), &c);
rgb[0] = c.red / 256;
rgb[1] = c.green / 256;
rgb[2] = c.blue / 256;
}
int main () {
int rgb[3], x, y;
XColor c;
Display* d = XOpenDisplay((char*)NULL);
getimage(c, d, rgb, x, y);
}
如何实现它以在 Windows 中运行?