You can check if the image's color model includes an alpha channel:
BufferedImage img = ImageIO.read(/* from somewhere */);
if (img.getColorModel().hasAlpha()) {undefined
// img has alpha channel
} else {undefined
// no alpha channel
}
Note that This code only detects images that have been saved with alpha channel. Images with an alpha channel may still be fully opaque (i.e. alpha = 1 for all pixels).
解决方案
You can check if the image's color model includes an alpha channel:
BufferedImage img = ImageIO.read(/* from somewhere */);
if (img.getColorModel().hasAlpha()) {undefined
// img has alpha channel
} else {undefined
// no alpha channel
}
Note that This code only detects images that have been saved with alpha channel. Images with an alpha channel may still be fully opaque (i.e. alpha = 1 for all pixels).
一周热门 更多>