Java Image Clear clear(Image img)

Here you can find the source of clear(Image img)

Description

clear

License

LGPL

Declaration

public static void clear(Image img) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

import java.awt.Image;

public class Main {
    public static void clear(Image img) {
        Graphics g = img.getGraphics();
        try {//  w  w w.  j a  va2  s.c om
            if ((g instanceof Graphics2D)) {
                ((Graphics2D) g).setComposite(AlphaComposite.Clear);
            } else {
                g.setColor(new Color(0, 0, 0, 0));
            }

            g.fillRect(0, 0, img.getWidth(null), img.getHeight(null));
        } finally {
            g.dispose();
        }
    }
}

Related

  1. clear(BufferedImage image, int col)
  2. clearImage(BufferedImage bi)
  3. clearImage(BufferedImage image)
  4. clearImage(BufferedImage img)
  5. clearImage(BufferedImage img)