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

相关文章:

  • 2021-06-19
  • 2021-11-10
  • 2021-12-13
  • 2021-05-26
  • 2021-11-08
  • 2022-02-02
猜你喜欢
  • 2021-09-23
  • 2021-06-16
  • 2021-06-21
  • 2022-01-07
  • 2021-07-21
  • 2021-07-14
  • 2021-04-24
相关资源
相似解决方案