机器人的getPixelColor(int x,int y)方法如何工作? [英] How does Robot's getPixelColor(int x, int y) method work?

查看:538
本文介绍了机器人的getPixelColor(int x,int y)方法如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方法 getPixelColor(int x,int y)从Robot类工作?我试过这个代码片段:

How exactly does the method getPixelColor(int x,int y) from the Robot class work? I tried this code fragment:

try 
{
     Robot robos = new Robot();
}
catch (AWTException e) 
{

}

for (int i = 0; i < 100; i++)
    robos.getPixelColor(0, 0);

System.out.println("fsadf");

在我的电脑上,这是一个核心2 duo,花了一秒或更少的时间执行打印语句。但是,当我在我的笔记本电脑(这是一个核心i3)上运行相同的代码时,需要花费更多的时间(约2-3秒)。

on my PC, which is a core 2 duo, and it took one second or less to execute the print statement. However, when I ran this same code on my laptop, which is a core i3, it took much more time (about 2-3 seconds).

背后?它是否与屏幕质量或类似的东西?如何解决这个问题?

What is the reason behind this? Does it have to do with the screen quality or something like that? How can I solve this problem?

推荐答案



how can i solve this problem?

不要使用机器人逐像素地获取颜色。使用Robot创建一个BufferedImage的屏幕。然后,您可以使用BufferedImage的getRGB()方法获取表示像素颜色的int值。然后,您可以使用此int或直接解析红色/绿色/蓝色值来创建颜色对象。

Don't use the Robot to get the colors pixel by pixel. Use the Robot the create a BufferedImage of the screen. Then you can use the getRGB() method of the BufferedImage to get the int value that represents the color of the pixel. You can then create a Color Object using this int or parse out the red/green/blue values directly.

这篇关于机器人的getPixelColor(int x,int y)方法如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆