快速从屏幕获取像素信息 [英] Getting pixel information from the screen quickly

查看:92
本文介绍了快速从屏幕获取像素信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,该应用程序需要获取屏幕上像素的颜色才能运行不同的自动化测试.

I am writing an application which needs to get the colors of pixels on the screen to run different automated tests.

(是的,我知道预先存在的自动化测试库.不,我不能使用它们.)

(Yes, I know of the preexisting automated testing libraries. No, I can't use them.)

目前,我正在用Java编写程序,该程序主要是这样做的:

Currently, I'm writing in Java and the program mostly does this:

Robot r = new Robot();
for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
        r.getPixelColor(i*20, j*20);

问题是它真的很慢.进行扫描大约需要一秒钟. (每像素10毫秒.)存在两个问题:(1)我希望它运行的很快,(2)在一秒钟之内,屏幕已经变了.由于各种原因,屏幕仅每半秒更新一次,因此唯一重要的问题是(1).

The problem with this is that it's really slow. It takes about a second to do that scan. (10ms per pixel.) There are two problems: (1) I would like it to be fast, and (2) within a second, the screen has changed already. For various reasons, the screen only updates once every half second, so the only issue that matters is (1).

有什么方法可以更快地获取像素颜色信息?如果没有Java库可以执行此操作,那么我很高兴听到有关C(或其他)方法的信息.

Is there any way to get pixel color information more quickly? If there are no Java libraries to do this, I'm happy to hear about C (or other) ways of doing this.

推荐答案

尝试使用Robot类的createScreenCapture(Rectangle screenRect)获取BufferedImage,然后使用BufferedImagegetRGB(int x, int y).那应该很快

Try using createScreenCapture(Rectangle screenRect) of Robot class to get the BufferedImage and then use getRGB(int x, int y) of BufferedImage. That should be fast

这篇关于快速从屏幕获取像素信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆