java robots.getPixelColor(x,y) 问题

发布于 2024-10-09 23:28:37 字数 626 浏览 4 评论 0原文

首先是代码:

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());
}

这不是我使用的确切代码,但它产生了相同的情况: 如果我在程序中运行此循环,并且整个循环的屏幕完全相同,它偶尔会输出类似以下内容:

255 255 255

...(相同颜色)

......

...

...

...

.. .

...

...

124 142 012 <---- 这是问题

255 255 255

据我所知,屏幕是静态的,但 robots.getPixelColor(x,y) 方法返回了一个错误集的价值观。

有人对此有任何经验或直觉吗?我能做些什么来防止这种情况发生吗?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若无相欠,怎会相见 2024-10-16 23:28:37

出于显而易见的原因;你的逻辑有问题。这里有一个想法:

假设你有一个宽度为 200px 的屏幕,假设你的算法检查屏幕边界之外的像素的颜色(即 201, 0)。 robots.getPixelColor 返回什么?它要么返回图像边界之外的颜色,要么返回某种无效结果。

话虽如此,请确保您的算法在图像的约束范围内检查有效像素;这可能是您的结果模糊不清的原因。

希望这有助于或带来适当的解决方案

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文