BitmapFilter.java 文件源码

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

项目:OmniSnitch 作者:
/**
 * Returns a glowed image of the provided icon. If the
 * provided name is already in the cache, the cached image
 * will be returned. Otherwise, the bitmap will be glowed and
 * cached under the provided name
 *
 * @param name The name of the bitmap - if name == null dont cache
 * @param src  The bitmap of the icon itself
 * @return Glowed bitmap
 */
public Bitmap getGlow(String name, int glowColor, Bitmap src) {
    if (name != null && mGlowCache.containsKey(name)) {
        return mGlowCache.get(name);
    } else {
        // An added margin to the initial image
        int margin = 0;
        int halfMargin = margin / 2;

        // The glow radius
        int glowRadius = 12;

        // Extract the alpha from the source image
        Bitmap alpha = src.extractAlpha();

        // The output bitmap (with the icon + glow)
        Bitmap bmp = Bitmap.createBitmap(src.getWidth() + margin,
                src.getHeight() + margin, Bitmap.Config.ARGB_8888);

        // The canvas to paint on the image
        Canvas canvas = new Canvas(bmp);

        Paint paint = new Paint();
        paint.setColor(glowColor);

        // Outer glow
        ColorFilter emphasize = new LightingColorFilter(glowColor, 1);
        paint.setColorFilter(emphasize);
        canvas.drawBitmap(src, halfMargin, halfMargin, paint);
        paint.setColorFilter(null);
        paint.setMaskFilter(new BlurMaskFilter(glowRadius, Blur.OUTER));
        canvas.drawBitmap(alpha, halfMargin, halfMargin, paint);

        if(name!=null){
            // Cache icon
            mGlowCache.put(name, bmp);
        }

        return bmp;
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号