ImageUtils.java 文件源码

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

项目:plg 作者:
/**
 * Given an image, this method extracts a color that is calculated as the
 * average of the colors of the image
 * 
 * @param image the given image
 * @return the "average" color
 */
public static Color getAverageColor(BufferedImage image) {
    if (image == null) {
        return null;
    }
    Image i = image.getScaledInstance(1, 1, BufferedImage.SCALE_SMOOTH);
    int[] pixels = new int[1];
    PixelGrabber pg = new PixelGrabber(i, 0, 0, 1, 1, pixels, 0, 1);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) { }
    int  c = pixels[0];
    int  red = (c & 0x00ff0000) >> 16;
    int  green = (c & 0x0000ff00) >> 8;
    int  blue = c & 0x000000ff;
    return new Color(red, green, blue);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号