clear BufferedImage - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage

Description

clear BufferedImage

Demo Code


//package com.java2s;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

public class Main {
    public static void clearImage(BufferedImage bufferedImage) {
        Graphics2D g = bufferedImage.createGraphics();
        g.setBackground(new Color(0, 0, 0, 0));
        g.clearRect(0, 0, bufferedImage.getWidth(),
                bufferedImage.getHeight());
        g.dispose();// w  ww . j  a  v  a  2 s.  c  om
    }

    public static void clearImage(BufferedImage bufferedImage, Color color) {
        Graphics2D g = bufferedImage.createGraphics();
        g.setBackground(new Color(0, 0, 0, 0));
        g.clearRect(0, 0, bufferedImage.getWidth(),
                bufferedImage.getHeight());
        g.setColor(color);
        g.fillRect(0, 0, bufferedImage.getWidth(),
                bufferedImage.getHeight());
        g.dispose();
    }
}

Related Tutorials