我有一些代码可以抓取屏幕上的像素区域并将它们转换为 BufferedImage 对象。问题是 - 它非常慢,所以我正在寻求支持以提高它的速度!
代码如下:
public BufferedImage getScreenPortion(Point topleft,Point bottomright){
int width = bottomright.x - topleft.x;
int height = bottomright.y - topleft.y;
BufferedImage bi = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
for(int p=0;p<height;p++){
for(int i= 0;i<width;i++){
Color pixel = robot.getPixelColor(topleft.x+i, topleft.y+p);
bi.setRGB(i, p, pixel.getRGB());
}
}
return bi;
}
我正在通过它: getScreenPortion(new Point(1081,824),new Point(1111,844));
这意味着我正在尝试获得大约 30x20 的区域 - 但它需要 7 秒的区域,这非常慢!