Here you can find the source of ConvToTransparentImage(BufferedImage src, float alpha)
public static BufferedImage ConvToTransparentImage(BufferedImage src, float alpha)
//package com.java2s; //License from project: Apache License import java.awt.AlphaComposite; import java.awt.Graphics2D; import java.awt.image.BufferedImage; public class Main { public static BufferedImage ConvToTransparentImage(BufferedImage src, float alpha) { // System.out.println("Conv to Transperent Image, apha value: " + // alpha); BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = dest.createGraphics(); int rule = AlphaComposite.SRC_OVER; AlphaComposite ac = AlphaComposite.getInstance(rule, alpha); g2.setComposite(ac);//w w w. ja va2 s. co m g2.drawImage(src, null, 0, 0); g2.dispose(); return dest; } public static void drawImage(BufferedImage srcImg, BufferedImage img2Draw, int w, int h) { if (w == -1) w = (int) (srcImg.getWidth() / 2); if (h == -1) h = (int) (srcImg.getHeight() / 2); System.out.println("AWT Image Wt: " + w + " And Ht: " + h); Graphics2D g2 = srcImg.createGraphics(); g2.drawImage(img2Draw, w, h, null); g2.dispose(); } }