Here you can find the source of fadeImageByShape(BufferedImage bimg, Shape arbshape, double alpha, int rule)
public static BufferedImage fadeImageByShape(BufferedImage bimg, Shape arbshape, double alpha, int rule)
//package com.java2s; //License from project: Apache License import java.awt.AlphaComposite; import java.awt.Graphics2D; import java.awt.Shape; import java.awt.image.BufferedImage; public class Main { static int COLORTYPE = BufferedImage.TYPE_INT_ARGB; public static BufferedImage fadeImageByShape(BufferedImage bimg, Shape arbshape, double alpha, int rule) { int ht = bimg.getHeight(), wd = bimg.getWidth(); BufferedImage bimgnew = new BufferedImage(wd, ht, COLORTYPE); Graphics2D g2d = (Graphics2D) bimgnew.createGraphics(); if (arbshape != null) g2d.setClip(arbshape);/* ww w . ja v a 2s. c o m*/ AlphaComposite ac = AlphaComposite.getInstance(rule, (float) alpha); g2d.setComposite(ac); g2d.drawImage(bimg, 0, 0, null); g2d.dispose(); // displayImage(bimgnew, "FadeImage: "+alpha); // String fileName = "test_output/fadeImg"+alpha+".png"; // SaveImageToFile(bimgnew, fileName, "PNG"); return bimgnew; } 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(); } }