效果展示:
原图
效果图:
原理: 使用某种颜色替换图像非透明部分,然后与原图合成最终效果。
步骤:
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;
}
LIGHTEN:
DARKEN:
缺点: 对非透明图片处理效果很差。处理效率很慢 40 ~ 70 ms 。