开发者

Fastest way to check if an image contain any (semi)transparent pixels?

Does anyone know is there a better way to check if some image contain a (semi)transparent pix开发者_运维知识库el beside going trough all pixels and check their alpha channel?

[pseudo]
    for each pixel in image:
        if pixel.alpha != 0xff:
            return true

Thanks in advance.


You could use BufferedImage.getType() or ColorModel.hasAlpha() to check if there is an alpha channel.

If there is an alpha channel, you will have to check the individual pixels.


yes there is a better way than simply iterating all pixels. if you already have a mip-map stored for the alpha channels you can check from top to bottom for any non-opaque pixels.

JAI supports these: put the alpha channel or the whole image into a javax.media.jai.ImageMIPMap then iterate its levels from top to bottom using getImage(int level)

some keywords for googling: gauss-laplace image pyramids, mipmaps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜