getpixel() java,java robot.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

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

解决方案

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值