gpt4 book ai didi

c - Windows 的库 "X11/Xlib.h"、 "X11/Xutil.h"、 "unistd.h"

转载 作者:行者123 更新时间:2023-11-30 20:04:15 25 4
gpt4 key购买 nike

我已经编写了一个 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 中运行?

最佳答案

您已经编写了一个 X11 程序。 X 是除 OS X 之外的类 UNIX 系统上图形显示的共识标准(但它也可免费用于 OS X)。

Windows 使用完全不同的图形显示 API。可以想象,您可以找到一种在 Windows 上运行的 X 实现,但 Microsoft 肯定不提供这种实现。由于您的程序非常短,因此最好的选择可能是使用 Windows API 重写它。

至于unistd.h(和time.h),我在您的程序中没有看到任何依赖于它的内容。如果您不打算重写程序,只需删除有问题的 #include 语句即可解决这部分问题。

关于c - Windows 的库 "X11/Xlib.h"、 "X11/Xutil.h"、 "unistd.h",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42587774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com