Here you can find the source of clearImage(final BufferedImage image)
public static void clearImage(final BufferedImage image)
//package com.java2s; //License from project: Open Source License import java.awt.AlphaComposite; import java.awt.Composite; import java.awt.Graphics2D; import java.awt.image.BufferedImage; public class Main { public static void clearImage(final BufferedImage image) { final Graphics2D g2d = image.createGraphics(); final Composite composite = g2d.getComposite(); g2d.setComposite(AlphaComposite.Clear); g2d.fillRect(0, 0, image.getWidth(), image.getHeight()); g2d.setComposite(composite);/* w w w . j a v a 2 s . c om*/ g2d.dispose(); } }