Here you can find the source of composite(BufferedImage bg, BufferedImage fg)
public static BufferedImage composite(BufferedImage bg, BufferedImage fg)
//package com.java2s; //License from project: Open Source License import java.awt.Graphics; import java.awt.image.BufferedImage; public class Main { public static BufferedImage composite(BufferedImage bg, BufferedImage fg) { BufferedImage result = copyImage(bg); Graphics g = result.getGraphics(); g.drawImage(fg, 0, 0, null);//w w w. j a v a 2 s. c o m g.dispose(); return result; } public static BufferedImage copyImage(BufferedImage source) { BufferedImage b = new BufferedImage(source.getWidth(), source.getHeight(), source.getType()); Graphics g = b.getGraphics(); g.drawImage(source, 0, 0, null); g.dispose(); return b; } }