Layer multiple BufferedImages on top of one another?

bufferedimage, java

Solution

I would say the best bet would be to take the buffered images, and create an additional one in order to have an object to append to. Then simply use the Graphics.drawImage() to place them on top of each other.

So something along these lines:

BufferedImage a = ImageIO.read(new File(filePath, "a.png"));
BufferedImage b = ImageIO.read(new File(filePath, "b.png"));
BufferedImage c = new BufferedImage(a.getWidth(), a.getHeight(), BufferedImage.TYPE_INT_ARGB);

Graphics g = c.getGraphics();
g.drawImage(a, 0, 0, null);
g.drawImage(b, 0, 0, null);

Problem

I have multiple transparent `BufferedImage` instances which I'd like to layer on top of each other (aka Photoshop layers) and bake into one `BufferedImage` output. How do I do this?

Original source

Related problems