Java tutorial
//package com.java2s; import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; public class Main { /** * Creates a shadow mask * @param image * @param shadowColor * @param shadowOpacity * @return */ private static BufferedImage createShadowMask(BufferedImage image, Color shadowColor, float shadowOpacity) { BufferedImage mask = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = mask.createGraphics(); g2d.drawImage(image, 0, 0, null); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN, shadowOpacity)); g2d.setColor(shadowColor); g2d.fillRect(0, 0, image.getWidth(), image.getHeight()); g2d.dispose(); return mask; } }