GraphicsUtils.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:vectorgraphics2d 作者:
/**
 * This method returns {@code true} if the specified image has the
 * possibility to store transparent pixels.
 * Inspired by http://www.exampledepot.com/egs/java.awt.image/HasAlpha.html
 * @param image Image that should be checked for alpha channel.
 * @return {@code true} if the specified image can have transparent pixels,
 *         {@code false} otherwise
 */
public static boolean hasAlpha(Image image) {
    ColorModel cm;
    // If buffered image, the color model is readily available
    if (image instanceof BufferedImage) {
        BufferedImage bimage = (BufferedImage) image;
        cm = bimage.getColorModel();
    } else {
        // 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) {
            return false;
        }
        // Get the image's color model
        cm = pg.getColorModel();
    }
    return cm.hasAlpha();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号