Here you can find the source of applyTransparency(BufferedImage src, float alpha)
public static BufferedImage applyTransparency(BufferedImage src, float alpha)
//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; } }