How does Robot's getPixelColor(int x, int y) method work?

廉价感情. 提交于 2019-11-28 05:09:02

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/7168839/how-does-robots-getpixelcolorint-x-int-y-method-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!