0

First off the code:

for (int i = 0; i < 25; i++)
{
robot.delay(1000);// wait 1 second
Color pixel_4 = robot.getPixelColor(x-15, 30);
System.out.println(pixel_4.getRed() + " " + pixel_4.getGreen() + " " + pixel_4.getBlue());
}

That is not the exact code I am using, but it produces the same situation: If I run this loop in a program and the screen is precisely the same for the entire loop it will occasionally output something like:

255 255 255

... (same color)

...

...

...

...

...

...

...

124 142 012 <---- this is the issue

255 255 255

As far as I can tell, the screen is static, but the robot.getPixelColor(x,y) method returned a false set of values.

Does anyone have any experience or intuition about this? Is there anything I can do to prevent it from happening?

Thanks

Dream Lane
  • 1,282
  • 5
  • 16
  • 27
  • Danger MK! Danger! (also java.awt.Robot is a class to facilitate very basic GUI testing or automated GUI interaction). – robert_x44 Jan 02 '11 at 02:33
  • 1
    I used the Robot class to capture multiple screenshots in a project aiming to help the end user to select a screen region from which to gain animated screenshots. The idea was for the user to take a screenshot while the object of interest was minimized, and another when it was visible. Then the comparison of the two images was used to predict the area of interest. It worked as expected. To put that another way. I think your code or logic is wrong - and that snippet is not enough to tell what is going wrong. I would recommend doing a test using static images first, and making it an SSCCE. – Andrew Thompson Jan 02 '11 at 02:38
  • 1
    I just tried the code and I have no problem, but I hardcoded the x/y values. Any chance your "x" value changes? – camickr Jan 02 '11 at 02:50
  • @Andrew Thompson: I'm not sure what an SSCCE is, but I will have to double check to be sure my image is static. – Dream Lane Jan 03 '11 at 00:51
  • @camickr: I am fairly certain the x value remains the same, but I will double check that as well. Thanks! – Dream Lane Jan 03 '11 at 00:52

1 Answers1

1

For obvious reasons; there is something wrong with your logic. Here is one thought:

Suppose you have a screen with width 200px, lets suppose your algorithm checks the color of a pixel that is outside of the bounds of the screen (i.e. 201, 0). What does robot.getPixelColor return? It would either return a color outside of the bounds of the image or return some kind of invalid result.

Having siad that, ensure that your algorithm checks valid pixels within the constraints of your image; this may be the cause of the obscurity of your results.

Hope this helps or leads to an appropriate solution

Adrian Carolli
  • 695
  • 6
  • 21