获得BufferedImage的透明版本

/**
 * Returns a transparent version of the passed <code>BufferedImage</code>.
 *
 * @param image image to be made transparent
 * @param transperancy value of the transparency
 * @return transparent <code>BufferedImage</code>
 */
public static BufferedImage getTransparentImage(BufferedImage image, float transperancy) {

    // Create the image using the
    BufferedImage transparentImage = new    BufferedImage(image.getWidth(), image.getHeight(), Transparency.TRANSLUCENT);

    // Get the images graphics.
    Graphics2D g = transparentImage.createGraphics();

    // Set the graphics composite to Alpha.
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transperancy));

    // Draw the passed image into the new transparent image.
    g.drawImage(image, null, 0, 0);

    // Free all system resources.
    g.dispose();

    // Return the image
    return transparentImage;
}

 

 获得BufferedImage的透明版本

你可能感兴趣的:(BufferedImage)