如何读取屏幕上的像素?
我正在尝试为网页游戏制作一个简单的机器人,所以我希望能够读取屏幕上像素的颜色。我已经在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.