如何从屏幕上读取像素

如何从屏幕上读取像素

本文介绍了如何从屏幕上读取像素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);

我认为上述代码会将(0,0)处像素的红色值存储到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.使用命令行工具,我的最终目标是制作bash脚本或applescript,因为我已经有了可以在屏幕上单击的命令行工具.

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.

推荐答案

glReadPixels仅关注从帧缓冲区(图形卡绘制的区域)读取像素.

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

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

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

这篇关于如何从屏幕上读取像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 07:05