CSS透明度】 java 怎么判断png图片是否是有透明度的

2022-02-25 15:20发布

6条回答


解决方案

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).


一周热门 更多>