Java Utililty Methods Image Clear

List of utility methods to do Image Clear

Description

The list of methods to do Image Clear are organized into topic(s).

Method

voidclear(BufferedImage image, int col)
clear
for (int i = 0; i < image.getWidth(); i++)
    for (int j = 0; j < image.getHeight(); j++)
        image.setRGB(i, j, col);
voidclear(Image img)
clear
Graphics g = img.getGraphics();
try {
    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));
...
voidclearImage(BufferedImage bi)
Sets all pixels of the given image to black and fully transparent (RGBA 0).
for (int x = 0; x < bi.getWidth(); x++) {
    for (int y = 0; y < bi.getHeight(); y++) {
        bi.setRGB(x, y, 0);
voidclearImage(BufferedImage image)
Convenience method for 'clearing' a BufferedImage.
int width = image.getWidth();
int height = image.getHeight();
int numpix = width * height;
int[] argbClear = new int[width * height];
for (int i = 0; i < width * height; i++) {
    argbClear[i] = 0x00000000;
image.setRGB(0, 0, width, height, argbClear, 0, width);
...
voidclearImage(BufferedImage img)
Clear a transparent image to 100% transparent
Graphics2D g2 = img.createGraphics();
g2.setComposite(AlphaComposite.Clear);
g2.fillRect(0, 0, img.getWidth(), img.getHeight());
g2.dispose();
BufferedImageclearImage(BufferedImage img)
Clears image does NOT make copy My "optimization" for not making new buffered image every time render is called
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();
...
voidclearImage(final BufferedImage image)
clear 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);
g2d.dispose();
voidclearMergedImagesCache()
clear Merged Images Cache
mergedImagesCache.clear();