Example usage for java.awt.image PixelGrabber getColorModel

List of usage examples for java.awt.image PixelGrabber getColorModel

Introduction

In this page you can find the example usage for java.awt.image PixelGrabber getColorModel.

Prototype

public synchronized ColorModel getColorModel() 

Source Link

Document

Get the ColorModel for the pixels stored in the array.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Image image = new ImageIcon("a.png").getImage();
    if (image instanceof BufferedImage) {
        BufferedImage bimage = (BufferedImage) image;
        System.out.println(bimage.getColorModel().getNumColorComponents());
    }/*from  w  w  w . j  a va 2s  . co  m*/

    PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
    }
    ColorModel cm = pg.getColorModel();
    System.out.println(cm.getNumColorComponents());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Image image = new ImageIcon("a.png").getImage();
    if (image instanceof BufferedImage) {
        BufferedImage bimage = (BufferedImage) image;
        System.out.println(bimage.getColorModel().hasAlpha());
    }//  w  ww. ja v  a 2  s  . c  o m

    PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
    }

    ColorModel cm = pg.getColorModel();
    System.out.println(cm.hasAlpha());
}

From source file:Main.java

/**
 * This method returns true if the specified image has transparent pixels
 *
 * @param image/* ww w.  j  a va2  s  .  c o  m*/
 * @return
 */
public static boolean hasAlpha(Image image) {
    // If buffered image, the colour model is readily available
    if (image instanceof BufferedImage) {
        return ((BufferedImage) image).getColorModel().hasAlpha();
    }

    // Use a pixel grabber to retrieve the image's colour model;
    // grabbing a single pixel is usually sufficient
    PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
    }

    // Get the image's colour model
    ColorModel cm = pg.getColorModel();
    return cm.hasAlpha();
}

From source file:ImageUtil.java

public static boolean hasAlpha(Image image) {
    // If buffered image, the color model is readily available
    if (image instanceof BufferedImage)
        return ((BufferedImage) image).getColorModel().hasAlpha();

    // Use a pixel grabber to retrieve the image's color model;
    // grabbing a single pixel is usually sufficient
    PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
    try {// w ww.  ja va2 s. co m
        pg.grabPixels();
    } catch (InterruptedException e) {
    }

    // Get the image's color model
    return pg.getColorModel().hasAlpha();
}

From source file:Main.java

public static boolean hasAlpha(Image image) {
    // If buffered image, the color model is readily available
    if (image instanceof BufferedImage) {
        BufferedImage bimage = (BufferedImage) image;
        return bimage.getColorModel().hasAlpha();
    }/*w ww .j  a  v  a2s .co  m*/

    // Use a pixel grabber to retrieve the image's color model;
    // grabbing a single pixel is usually sufficient
    PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
    }

    // Get the image's color model
    ColorModel cm = pg.getColorModel();
    return cm.hasAlpha();
}

From source file:de.laures.cewolf.util.ImageHelper.java

public static boolean hasAlpha(Image image) {
    if (image instanceof BufferedImage) {
        return ((BufferedImage) image).getColorModel().hasAlpha();
    }//from   www  .  j  ava  2s . c om
    PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    ColorModel cm = pg.getColorModel();
    if (cm == null) {
        return false;
    }
    return cm.hasAlpha();
}

From source file:com.jaeksoft.searchlib.util.ImageUtils.java

public static boolean hasAlpha(Image image) throws InterruptedException {
    if (image instanceof BufferedImage)
        return ((BufferedImage) image).getColorModel().hasAlpha();
    PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
    pg.grabPixels();/*from   w  ww  .  ja  v a2  s.  c  o m*/
    return pg.getColorModel().hasAlpha();
}

From source file:ImageUtils.java

/**
 * This method returns true if the specified image has transparent pixels
 * This snippet was taken from: http://www.exampledepot.com/egs/java.awt.image/HasAlpha.html
 * @param image/*from  www  . j a va  2s .  co m*/
 * @return True if the image has any transparency
 */
public static boolean hasAlpha(Image image) {
    // If buffered image, the color model is readily available
    if (image instanceof BufferedImage) {
        BufferedImage bimage = (BufferedImage) image;
        return bimage.getColorModel().hasAlpha();
    }

    // Use a pixel grabber to retrieve the image's color model;
    // grabbing a single pixel is usually sufficient
    PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
    }

    // Get the image's color model
    ColorModel cm = pg.getColorModel();
    return cm.hasAlpha();
}

From source file:ImageUtils.java

/**
 * Determines if the image has transparent pixels.
 * /*  w w w.j ava2  s .c o m*/
 * @param image The image to check for transparent pixel.s
 * @return <code>true</code> of <code>false</code>, according to the result
 */
public static boolean hasAlpha(Image image) {
    try {
        PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
        pg.grabPixels();

        return pg.getColorModel().hasAlpha();
    } catch (InterruptedException e) {
        return false;
    }
}

From source file:net.pms.medialibrary.commons.helpers.FileImportHelper.java

private static boolean hasAlpha(Image image) {
    // If buffered image, the color model is readily available
    if (image instanceof BufferedImage) {
        BufferedImage bimage = (BufferedImage) image;
        return bimage.getColorModel().hasAlpha();
    }//from   ww w . j a va  2s  . co  m

    // Use a pixel grabber to retrieve the image's color model;
    // grabbing a single pixel is usually sufficient
    PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
    }

    // Get the image's color model
    ColorModel cm = pg.getColorModel();
    return cm.hasAlpha();
}