fusion of images without using of buffereimage

61 views Asked by At

I would like to merge many images into one, so i instantiate a bufferedImage to do this :

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);

And I have a heap space memory error. So I need to know: How can I fix it?

0

There are 0 answers