Java BufferedImage Color Set changeTranslucentImage(BufferedImage img, float transperancy)

Here you can find the source of changeTranslucentImage(BufferedImage img, float transperancy)

Description

Change a image with a certain transparency.

License

Apache License

Parameter

Parameter Description
url a parameter
transperancy a parameter

Return

BufferedImage

Declaration

public static BufferedImage changeTranslucentImage(BufferedImage img, float transperancy) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.awt.AlphaComposite;

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

public class Main {
    private static BufferedImage bimg;
    private static Graphics2D g2;

    /**//from w w w .j  a v  a2 s  . c  om
     * Change a image with a certain transparency.
     * 
     * @param url
     * @param transperancy
     * @return BufferedImage
     */
    public static BufferedImage changeTranslucentImage(BufferedImage img, float transperancy) {
        bimg = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TRANSLUCENT);
        g2 = bimg.createGraphics();
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transperancy));
        g2.drawImage(img, null, 0, 0);
        g2.dispose();

        return bimg;
    }
}

Related

  1. changeColor(BufferedImage image, Color color, Color replacement_color)
  2. changeColor(BufferedImage image, Color replacement)
  3. changeColor(BufferedImage image, String hexval)
  4. changeRGBSaturation(final BufferedImage image, final double s)
  5. changeToTypeIntRGB(BufferedImage image)