不使用buffereimage融合图像

时间:2015-06-25 13:30:52

标签: java image bufferedimage

我想将多个图像合并为一个,所以我实例化一个bufferedImage来执行此操作:

for (int i=0;i<listImagetmp.size();i++) {   
    if (listImagetmp.get(i)!=null) {
        Image src = listImagetmp.get(i);  


            BufferedImage bimage = new BufferedImage(src.getWidth(null), src.getHeight(null), BufferedImage.TYPE_INT_RGB);

            // Draw the image on to the buffered image
            Graphics2D bGr = bimage.createGraphics();
            bGr.drawImage(src, 0, 0, null);
            bGr.dispose();
            int[] pixels = ((DataBufferInt) bimage.getRaster().getDataBuffer()).getData();
            for(int x =0; x<bimage.getWidth();x++){
                for(int y =0; y<bimage.getHeight();y++){
                    int newRGBValue = pixels[y * bimage.getWidth() + x];
                    int oldValue = bufferedImage.getRGB(x, y);
                    if((newRGBValue > oldValue) && (oldValue != -16777216) && (newRGBValue == 16777215)){
                        newRGBValue = oldValue;
                    }
                    bufferedImage.setRGB(x, y, newRGBValue);
                }
            }

    }
}

node = new PImage(bufferedImage);
bufferedImage.flush();
bufferedImage.getGraphics().dispose();
bufferedImage = null;
PImage node2 =  (PImage) node.clone();     // Clonage
node = null;
getCanvas().getLayer().addChild(node2);

我有一个堆空间内存错误。 所以我需要知道: 我该如何解决?

0 个答案:

没有答案