Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting pixel information from the screen quickly [duplicate]

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

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

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

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.

like image 387
michael dillard Avatar asked Dec 01 '11 23:12

michael dillard


1 Answers

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

like image 183
havexz Avatar answered Oct 11 '22 20:10

havexz