Here you can find the source of TransformGrayToTransparency(BufferedImage image)
private static Image TransformGrayToTransparency(BufferedImage image)
//package com.java2s; //License from project: Open Source License import java.awt.Image; import java.awt.Toolkit; import java.awt.image.BufferedImage; import java.awt.image.FilteredImageSource; import java.awt.image.ImageFilter; import java.awt.image.ImageProducer; import java.awt.image.RGBImageFilter; public class Main { private static Image TransformGrayToTransparency(BufferedImage image) { ImageFilter filter = new RGBImageFilter() { public final int filterRGB(int x, int y, int rgb) { if (rgb == 0) { return 0; }/*from w ww . jav a2 s .c om*/ return rgb; } }; ImageProducer ip = new FilteredImageSource(image.getSource(), filter); return Toolkit.getDefaultToolkit().createImage(ip); } }