如何读取屏幕上的像素?

发布于 2024-10-07 10:34:42 字数 430 浏览 0 评论 0原文

我正在尝试为网页游戏制作一个简单的机器人,所以我希望能够读取屏幕上像素的颜色。我已经在 Windows 上使用 GetPixel() 完成了此操作,但我似乎无法在 OS X 上弄清楚它。我一直在网上查找并遇到了 glReadPixel。当我在XCode中制作一个简单的命令行工具时,我输入了以下代码。但是,我似乎无法使其发挥作用。我不断收到 EXC_BAD_ACCESS 错误:

GLfloat r;
glReadPixels(0, 0, 1, 1, GL_RED, GL_FLOAT, &r);

我认为上面的代码会将 (0,0) 处像素的红色值存储到 r 中。哦,我想避免采用屏幕截图方法,因为那很慢。有什么帮助吗?

PS 使用命令行工具,我的最终目标是制作 bash 脚本或 applescript,因为我已经有了一个可以在屏幕上单击的命令行工具。

I am trying to make a simple bot for a web game, so I would like to be able to read the color of a pixel on the screen. I've done this on Windows with GetPixel(), but I can't seem to figure it out on OS X. I been looking online and came across glReadPixel. When I made a simple command line tool in XCode, I put in the following code. However, I cannot seem to make it work. I keep getting a EXC_BAD_ACCESS error from this:

GLfloat r;
glReadPixels(0, 0, 1, 1, GL_RED, GL_FLOAT, &r);

I thought the above code would store the red value of the pixel at (0,0) into r. Oh, I'd like to avoid take a screen shot approach because that is slow. Any help?

P.S. With the command line tool, my end goal is to make a bash script or an applescript, since I already have a command line tool that can click on the screen.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

删除会话 2024-10-14 10:34:42

glReadPixels 只关心从帧缓冲区(显卡绘制的区域)读取像素。

从“屏幕”读取像素与OpenGL完全无关。为此,您需要系统特定的功能。

glReadPixels is only concerned about reading a pixel from the frame buffer (the area into which your graphics card draws).

Reading pixels from the "screen" is not related to OpenGL at all. You need system-specific functions for that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文