Here you can find the source of clearImage(BufferedImage img)
Parameter | Description |
---|---|
img | the image to clear |
public static BufferedImage clearImage(BufferedImage img)
//package com.java2s; //License from project: Open Source License import java.awt.AlphaComposite; import java.awt.Graphics2D; import java.awt.image.BufferedImage; public class Main { /**/*from www . ja v a 2 s .c o m*/ * Clears image does NOT make copy My "optimization" for not making new buffered image every * time render is called * @param img the image to clear * * @return the cleared image */ public static BufferedImage clearImage(BufferedImage img) { if (img == null) { return null; } Graphics2D g = img.createGraphics(); g.setComposite(AlphaComposite.Clear); g.fillRect(0, 0, img.getWidth(), img.getHeight()); g.setComposite(AlphaComposite.SrcOver); g.dispose(); return img; } }