Robot 的 getPixelColor(int x, int y) 方法如何工作?
究竟如何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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要使用机器人逐像素获取颜色。使用机器人创建屏幕的 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.