Java 获取像素区域并转换为图像 - 如何才能更有效?
我有一些代码将抓取屏幕上的像素区域并将它们转换为 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 秒,这实在是太慢了!
I have some code which will grab an area of pixels on the screen and turn them into a BufferedImage object. The thing is - it is MASSIVELY slow, so I am looking for support in increasing its speed!
The code is as follows:
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;
}
and I am passing it : getScreenPortion(new Point(1081,824),new Point(1111,844));
which means I am trying to get an areas approximately 30x20 - yet it is taking in the region of 7 seconds which is horrendously slow!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
修复了它 - 我现在改为使用:
Fixed it - I now instead use: