Java BufferedImage to Transparent makeColorTransparent(BufferedImage image, Color color)

Here you can find the source of makeColorTransparent(BufferedImage image, Color color)

Description

make Color Transparent

License

Apache License

Declaration

public static BufferedImage makeColorTransparent(BufferedImage image, Color color) 

Method Source Code


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

import java.awt.AlphaComposite;
import java.awt.Color;

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage makeColorTransparent(BufferedImage image, Color color) {
        BufferedImage dimg = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);

        Graphics2D g = dimg.createGraphics();
        g.setComposite(AlphaComposite.Src);
        g.drawImage(image, null, 0, 0);/*from   w  ww.  j a  va2  s .  co  m*/
        g.dispose();
        for (int i = 0; i < dimg.getHeight(); i++) {
            for (int j = 0; j < dimg.getWidth(); j++) {
                if (dimg.getRGB(j, i) == color.getRGB()) {
                    dimg.setRGB(j, i, 0x8F1C1C);
                }
            }
        }
        return dimg;
    }
}

Related

  1. getTransparentImage(BufferedImage i)
  2. getTransperentImage(BufferedImage origImage, BufferedImage compImg)
  3. makeColorTransparent(BufferedImage im, final Color color)
  4. makeColorTransparent(BufferedImage im, final Color color)
  5. makeColorTransparent(final BufferedImage im, final Color color)
  6. makeColorTransparent(final BufferedImage im, final Color colorToMakeTransparent, final int tolerance)
  7. makeColorTransparent(Image im, final Color color)
  8. makeColorTransparent(Image image, final Color transparentColor)