5

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.

michael dillard
  • 449
  • 2
  • 5
  • 14
  • maybe this solution can help you : http://stackoverflow.com/questions/7168839/how-does-robots-getpixelcolorint-x-int-y-method-work – Anthea Dec 02 '11 at 00:03

2 Answers2

6

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

havexz
  • 9,550
  • 2
  • 33
  • 29
2

You might want to try using r.createScreenCapture() to get the screen at once, and then iterate over the resulting image buffer. That may be faster than repeatedly calling getPixelColor(). Otherwise, definitely a C program that grabs screen capture would be faster than java.

TJD
  • 11,800
  • 1
  • 26
  • 34