java robot.getPixelColor(x,y) question

心已入冬 提交于 2019-12-11 17:31:02

问题


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


回答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



来源:https://stackoverflow.com/questions/4576762/java-robot-getpixelcolorx-y-question

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!