Java BufferedImage Operation fadeImageByShape(BufferedImage bimg, Shape arbshape, double alpha, int rule)

Here you can find the source of fadeImageByShape(BufferedImage bimg, Shape arbshape, double alpha, int rule)

Description

fade Image By Shape

License

Apache License

Declaration

public static BufferedImage fadeImageByShape(BufferedImage bimg, Shape arbshape, double alpha, int rule) 

Method Source Code


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

Related

  1. DuplicateBufferedImage(BufferedImage bi)
  2. duplicateImage(BufferedImage image)
  3. dye(BufferedImage image, Color color)
  4. ensureIntRGB(final BufferedImage img)
  5. ensureRGBAImage(BufferedImage img)
  6. fadeImages(BufferedImage source1, BufferedImage source2, BufferedImage target, int relX, int targetX)
  7. fakeAOI(final BufferedImage pImage, final Rectangle pSourceRegion)
  8. findavg(BufferedImage bimg)
  9. findColor(BufferedImage image, int startX, int startY, int dirX, int dirY, int colorIndex)