Java BufferedImage Transparent applyTransparency(BufferedImage src, float alpha)

Here you can find the source of applyTransparency(BufferedImage src, float alpha)

Description

apply Transparency

License

Open Source License

Declaration

public static BufferedImage applyTransparency(BufferedImage src, float alpha) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage applyTransparency(BufferedImage src, float alpha) {

        BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = dest.createGraphics();

        g.drawImage(src, 0, 0, null);//  w ww .j av  a 2  s  .  co m

        AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.DST_IN, 1.0f);
        g.setComposite(ac);

        float a = Math.max(0, Math.min(1, alpha));
        g.setColor(new Color(0f, 0f, 0f, a));
        g.fillRect(0, 0, dest.getWidth(), dest.getHeight());

        g.dispose();

        return dest;
    }
}

Related

  1. ApplyTransparency(BufferedImage image, Image mask)
  2. bordersNonTransparentPixel(BufferedImage data, int wid, int hei, boolean[] traced, int x, int y)
  3. ConvToTransparentImage(BufferedImage src, float alpha)
  4. cutTransparentBorder(BufferedImage src)
  5. fixTransparency(String var0, BufferedImage var1)