You can check if the image's color model includes an alpha channel:
BufferedImage img = ImageIO.read(/* from somewhere */);
if (img.getColorModel().hasAlpha()) {
// img has alpha channel
} else {
// 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).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…