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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With