Robot 的 getPixelColor(int x, int y) 方法如何工作?

发布于 2024-11-30 20:23:46 字数 537 浏览 3 评论 0原文

究竟如何Robot 类中的方法 getPixelColor(int x,int y) 有效吗?我尝试了以下代码片段:

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

}

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

System.out.println("fsadf");

在我的 PC(Core 2 Duo)上,执行打印语句只需要一秒或更短的时间。然而,当我在我的笔记本电脑(Core i3)上运行相同的代码时,花费了更多的时间(大约 2-3 秒)。

这背后的原因是什么?与屏幕质量或类似的东西有关系吗?我该如何解决这个问题?

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");

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?

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

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

发布评论

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

评论(1

猫性小仙女 2024-12-07 20:23:46

如何解决这个问题?

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

how can i solve this problem?

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.

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