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:com.aurel.track.attachment.AttachBL.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  w  w  w.  j a va 2s. c om*/

    // 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:GifEncoder.java

/** Constructs a new GifEncoder using an 8-bit AWT Image.
 The image is assumed to be fully loaded. */
public GifEncoder(Image img) {
    width = img.getWidth(null);/*w w  w  .j  a va  2  s . c  om*/
    height = img.getHeight(null);
    pixels = new byte[width * height];
    PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height, false);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        System.err.println(e);
    }
    ColorModel cm = pg.getColorModel();
    if (cm instanceof IndexColorModel) {
        pixels = (byte[]) (pg.getPixels());
        // hpm
        IndexColorModel icm = (IndexColorModel) cm;
        setTransparentPixel(icm.getTransparentPixel());
    } else
        throw new IllegalArgumentException("IMAGE_ERROR");
    IndexColorModel m = (IndexColorModel) cm;
    int mapSize = m.getMapSize();
    r = new byte[mapSize];
    g = new byte[mapSize];
    b = new byte[mapSize];
    m.getReds(r);
    m.getGreens(g);
    m.getBlues(b);
    interlace = false;
    pixelIndex = 0;
    numPixels = width * height;
}

From source file:lucee.runtime.img.Image.java

/**
 * This method returns true if the specified image has transparent pixels
 * @param image/*from w  ww. j  a  v a 2 s . co  m*/
 * @return
 */
public static boolean hasAlpha(java.awt.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:org.wings.SImageIcon.java

protected static String determineMimeType(ImageIcon imageIcon) {
    String mimeType = extractMimeTypeFromPath(imageIcon.getDescription());
    if (mimeType != null)
        return mimeType;
    PixelGrabber pg = new PixelGrabber(imageIcon.getImage(), 0, 0, 1, 1, false);
    try {/*from w  ww . j  a  va2s. c  o m*/
        pg.grabPixels();
    } catch (InterruptedException e) {
        log.warn("interrupted waiting for pixels!");
    }

    mimeType = "image/";
    if (!(pg.getColorModel() instanceof IndexColorModel))
        mimeType += ImageExternalizer.FORMAT_PNG;
    else
        mimeType += ImageExternalizer.FORMAT_GIF;

    return mimeType;
}

From source file:org.yccheok.jstock.gui.Utils.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();
    }//ww  w . jav a 2 s. c o 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:ro.nextreports.designer.util.ImageUtil.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   w w  w  .ja v a2 s .  c  o 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) {
        e.printStackTrace();
    }

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