Clear a transparent image to 100% transparent - Java 2D Graphics

Java examples for 2D Graphics:Image

Description

Clear a transparent image to 100% transparent

Demo Code

/*//from  w ww .j  av  a2  s.  c o  m
 * @(#)EffectUtils.java   1.2 07/12/12
 *
 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
//package com.java2s;
import java.awt.AlphaComposite;
import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

public class Main {
    /**
     * Clear a transparent image to 100% transparent
     * 
     * @param img
     *            The image to clear
     */
    static void clearImage(BufferedImage img) {
        Graphics2D g2 = img.createGraphics();
        g2.setComposite(AlphaComposite.Clear);
        g2.fillRect(0, 0, img.getWidth(), img.getHeight());
        g2.dispose();
    }
}

Related Tutorials