The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.awt.image  [21 examples] > Images  [6 examples]

e662. Getting the Color Model of an Image

    // This method returns the color model of an image
    public static ColorModel getColorModel(Image image) {
        // If buffered image, the color model is readily available
        if (image instanceof BufferedImage) {
            BufferedImage bimage = (BufferedImage)image;
            return bimage.getColorModel();
        }
    
        // 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) {
         }
        ColorModel cm = pg.getColorModel();
        return cm;
    }

 Related Examples
e660. Creating an Image from an Array of Color-Indexed Pixel Values
e661. Determining If an Image Has Transparent Pixels
e663. Getting the Transparent Pixel and Number of Colors Used in a GIF Image
e664. Getting a Sub-Image of an Image
e665. Filtering the RGB Values in an Image

See also: Buffered Images    Effects    Volatile Images   


© 2002 Addison-Wesley.