Image has Alpha Component - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Color

Description

Image has Alpha Component

Demo Code


//package com.java2s;

import java.awt.Image;

import java.awt.image.PixelGrabber;

public class Main {
    private static final boolean hasAlphaComponent(Image img) {
        // Use a pixel grabber to retrieve the image's color model;
        // grabbing a single pixel
        PixelGrabber pg = new PixelGrabber(img, 0, 0, 1, 1, false);
        try {//  w ww. j  ava2 s. c  o  m
            //grabbed the pixel
            pg.grabPixels();

            //checking if has ALPHA component
            if (pg.getColorModel().hasAlpha())
                return true;
            else
                return false;
        } catch (InterruptedException e) {
            System.out
                    .println("Unable to retrieve APLHA information for Image ");
            return false;
        }

    }
}

Related Tutorials