// This method returns true if the specified image has transparent pixels
    public 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();
        }
    
        // 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();
    }

 

Related Examples

相关文章:

  • 2022-12-23
  • 2022-03-08
  • 2021-12-15
  • 2021-07-11
  • 2022-01-20
  • 2022-12-23
  • 2022-02-04
  • 2021-12-26
猜你喜欢
  • 2021-10-23
  • 2021-11-20
  • 2022-12-23
  • 2021-09-20
  • 2021-06-29
  • 2021-11-20
  • 2021-12-15
相关资源
相似解决方案