How to read a pixel off of the screen?

て烟熏妆下的殇ゞ 提交于 2019-12-22 05:34:11

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4425668/how-to-read-a-pixel-off-of-the-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!