1. 程式人生 > >e662. 取的圖像的色彩模型

e662. 取的圖像的色彩模型

red ali buffere ati aci bgcolor model pad bim

// 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

e662. 取的圖像的色彩模型