Java获取像素区域并转化为图像-如何提高效率?

Java获取像素区域并转化为图像-如何提高效率?,java,swing,awt,sun,Java,Swing,Awt,Sun,我有一些代码可以抓取屏幕上的一个像素区域,并将它们转换为BuffereImage对象。问题是-它的速度非常慢,所以我正在寻找支持来提高它的速度 代码如下: public BufferedImage getScreenPortion(Point topleft,Point bottomright){ int width = bottomright.x - topleft.x; int height = bottomright.y - topleft.y; Buffered

我有一些代码可以抓取屏幕上的一个像素区域,并将它们转换为BuffereImage对象。问题是-它的速度非常慢,所以我正在寻找支持来提高它的速度

代码如下:

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;


}
public buffereImage GetScreenPart(点左上角,点右下角){
int width=右下角.x-左上角.x;
int height=右下角.y-左上角.y;
BuffereImage bi=新的BuffereImage(宽度、高度、BuffereImage.TYPE_INT_RGB);

对于(int p=0;p修复了它-我现在使用:

Rectangle screenRect = new Rectangle(topleft.x, topleft.y, width, height);
BufferedImage grid = robot.createScreenCapture(screenRect);

是否有理由将其标记为“oracle”?修复了它-我现在改为使用:要创建代码块,缩进四个空格。不要使用[code][/code]。+1可能会找到一些相关示例。