decode BufferedImage Alpha Exponent - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Color

Description

decode BufferedImage Alpha Exponent

Demo Code


//package com.java2s;
import java.awt.image.BufferedImage;

public class Main {
    public static void decodeAlphaExponent(BufferedImage image) {
        int rgb;/*from   w  ww  .j  a v a  2s  .  c  o m*/
        float a, r, g, b;
        for (int y = 0; y < image.getHeight(); ++y) {
            for (int x = 0; x < image.getWidth(); ++x) {
                rgb = image.getRGB(x, y);
                a = ((rgb >> 24) & 0xff) / 255.0f;
                r = ((rgb >> 16) & 0xff);
                g = ((rgb >> 8) & 0xff);
                b = (rgb & 0xff);

                r = r * a;
                g = g * a;
                b = b * a;

                r = Math.min(r, 255);
                g = Math.min(g, 255);
                b = Math.min(b, 255);

                rgb = (255 << 24) | ((int) r << 16) | ((int) g << 8)
                        | ((int) b << 0);
                image.setRGB(x, y, rgb);
            }
        }
    }
}

Related Tutorials