图片边缘增加光晕效果

来源:互联网 发布:电脑时钟同步软件 编辑:程序博客网 时间:2024/04/30 00:42

效果展示:

原图原图 效果图:光晕效果图


原理: 使用某种颜色替换图像非透明部分,然后与原图合成最终效果。

步骤:

1. 底色替换 , 得到如下结果:

底色图

2.与原图合成,得到最终效果

处理代码:

 /**     *     * @param map  image     * @param haloWidthPx halo width, unit in pixel     * @param haloColor halo color     * @return source image if haloWidth is zero     */    public static Bitmap addHaloForImage(Bitmap map , int haloWidthPx ,int haloColor){        if(isValidBitmap(map)){           if(haloWidthPx < 0){               haloWidthPx = 20;           }            if(haloWidthPx != 0){                // method one                Paint p = new Paint();                p.setColor(haloColor);                p.setAntiAlias(true);                p.setFilterBitmap(true);                MaskFilter bmf = new BlurMaskFilter(haloWidthPx, BlurMaskFilter.Blur.SOLID);                p.setMaskFilter(bmf);                Bitmap d = Bitmap.createBitmap(map.getWidth()+haloWidthPx * 2,map.getHeight()+haloWidthPx*2, Bitmap.Config.ARGB_8888);                Canvas c = new Canvas(d);                c.drawBitmap(map.extractAlpha(),haloWidthPx,haloWidthPx,p);                p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));                c.drawBitmap(map,haloWidthPx,haloWidthPx,p);                map.recycle();                System.gc();                // end                return d;            }        }        return map;    }


修改PorterDuff Mode 可以得到不同的效果,下面给出效果图:

LIGHTEN:lighten_sss DARKEN:

缺点: 对非透明图片处理效果很差。处理效率很慢 40 ~ 70 ms 。


0 0
原创粉丝点击