java robot.getPixelColor(x,y)问题 [英] java robot.getPixelColor(x,y) question
问题描述
首先编写代码:
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
255 255 255
...(相同颜色)
...
...
...
...
...
...
...
124 142 012< ----这就是问题
124 142 012 <---- this is the issue
255 255 255
255 255 255
据我所知,屏幕是静态的,但是robot.getPixelColor(x,y)方法返回了一组错误的值.
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?
谢谢
推荐答案
出于明显的原因;您的逻辑有问题.这是一个想法:
For obvious reasons; there is something wrong with your logic. Here is one thought:
假设您有一个宽度为200像素的屏幕,请假设您的算法检查的是屏幕边界(即201、0)之外的像素的颜色. robot.getPixelColor返回什么?它将返回超出图像范围的颜色,或者返回某种无效的结果.
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
这篇关于java robot.getPixelColor(x,y)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!