I'm in a situation where I'm not allowed to use AWT libraries on a server but need to merge two images. I know only of one method in Java which is using java.awt.Graphics.drawImage
and java.awt.image.BufferedImage
.
Is it possible to merge two images not using AWT?
AWT-based example code:
try {
BufferedImage image = ImageIO.read(new File("a.png"));
BufferedImage overlay = ImageIO.read(new File("b.png"));
int width = Math.max(image.getWidth(), overlay.getWidth());
int height = Math.max(image.getHeight(), overlay.getHeight());
BufferedImage combination = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics g = combination.getGraphics();
g.drawImage(image, 0, 0, null);
g.drawImage(overlay, 0, 0, null);
ImageIO.write(combination, "png", new File("c.png"));
}
catch (IOException ioe) {
}