e662. 取的图像的色彩模型

// 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
posted @ 2018-09-02 21:48  borter  阅读(153)  评论(0编辑  收藏  举报