Java BufferedImage Transparent ConvToTransparentImage(BufferedImage src, float alpha)

Here you can find the source of ConvToTransparentImage(BufferedImage src, float alpha)

Description

Conv To Transparent Image

License

Apache License

Declaration

public static BufferedImage ConvToTransparentImage(BufferedImage src, float alpha) 

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 {
    public static BufferedImage ConvToTransparentImage(BufferedImage src, float alpha) {
        // System.out.println("Conv to Transperent Image, apha value: " +
        // alpha);
        BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = dest.createGraphics();
        int rule = AlphaComposite.SRC_OVER;
        AlphaComposite ac = AlphaComposite.getInstance(rule, alpha);
        g2.setComposite(ac);//w  w w. ja va2  s.  co  m
        g2.drawImage(src, null, 0, 0);
        g2.dispose();
        return dest;
    }

    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();
    }
}

Related

  1. ApplyTransparency(BufferedImage image, Image mask)
  2. applyTransparency(BufferedImage src, float alpha)
  3. bordersNonTransparentPixel(BufferedImage data, int wid, int hei, boolean[] traced, int x, int y)
  4. cutTransparentBorder(BufferedImage src)
  5. fixTransparency(String var0, BufferedImage var1)
  6. makeTransparency(BufferedImage image, int color)
  7. makeTranspBufferedImage(Image image)