Robot getpixelColor returns wrong color sometimes...

Hey

I ve got a problem. I read Pixels from a Game with the Robot getPixelColor method. Sometimes it returns right values, sometimes wrong! I check some pixels if they are white. The pixels dont move, so this same pixels are white everytime!.

Now sometimes he returns wrong colors. Instead of 255,255,255 ...it returns 0,12,25 or something like that. (with the same x, y coordinate).

My assumption is: My code is like following

CheckPixel(MyRobot.getPixelColor(30,40);

CheckPixel(MyRobot.getPixelColor(31,45);

CheckPixel(MyRobot.getPixelColor(36,20);

CheckPixel(MyRobot.getPixelColor(51,70);

...

..

Now it has to return 255,255,255 but somtimes its not working, he return 0,0.12 .... 0,0,15..... 255,255,255 .. or something like that

Could it be, that java does not refresh the robot object so fast when I call getPixelColor so fast in a row?

Is there a command with which I force Java to wait until the pointer is on the right x,y coordinate? Except of Thread.Sleep();

Thank you for your help..

[1081 byte] By [Lumpeh123a] at [2007-11-26 20:23:33]
# 1
[url= http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Robot.html#getPixelColor(int,%20int)]getPixelColor()[/url]You know the method needs coordinates relative to the entire screen, right?
CaptainMorgan08a at 2007-7-10 0:49:36 > top of Java-index,Java Essentials,Java Programming...
# 2
I take the pixels from a Fullscreen game, so the pixels are always at the same position
Lumpeh123a at 2007-7-10 0:49:36 > top of Java-index,Java Essentials,Java Programming...
# 3
Can you post a short example that demonstrates the problem?
CaptainMorgan08a at 2007-7-10 0:49:36 > top of Java-index,Java Essentials,Java Programming...
# 4

ok I try:

...

Robot r = new Robot();

int x, int y;

x = getItSomehwere();

y = getitsomehwere();

for (int i= 0, i< 20; i++) {

if (isThatPixelsWhite(x, y) != 0) {

DoSomething;

}

}

public int isThatPixelsWhite(int x, int y) {

if (

r.getPixelColor(x+5,y+15).equals(Color.WHITE) &&

r.getPixelColor(x+7,y+19).equals(Color.WHITE) &&

r.getPixelColor(x+9,y+11).equals(Color.WHITE) &&

r.getPixelColor(x+21,y+5).equals(Color.WHITE) &&

r.getPixelColor(x+13,y+2).equals(Color.WHITE) &&

r.getPixelColor(x+23,y+7).equals(Color.WHITE) &&

r.getPixelColor(x+9,y+9).equals(Color.WHITE) &&

r.getPixelColor(x+10,y+21).equals(Color.WHITE) &&

r.getPixelColor(x+11,y+22).equals(Color.WHITE)

) return 1;

return 0;

}

Thats the relevant code.

I guess the fast calling of getPixelColor in this if struct (in Method isthatPixelsWhite) overburd java ..

Lumpeh123a at 2007-7-10 0:49:36 > top of Java-index,Java Essentials,Java Programming...
# 5
my workaround is to sleep(30) my thread before testing a new x,y pair with the method..this seems to work but i think this is not an appropriate solution
Lumpeh123a at 2007-7-10 0:49:36 > top of Java-index,Java Essentials,Java Programming...