图片边缘增加光晕效果

本文深入探讨了图像处理技术的应用,包括颜色替换、合成、特效制作等,并详细介绍了相关算法实现过程及优化策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果展示:

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


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

步骤:

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 。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值