今天无聊逛GaytHub时,无意发现了一个开源库
看下官方的示例图:
这个库是所有Android实现高斯模糊效率最高的方式,底层使用了RenderScript进行图片了算法。
下面是我做的Demo:
---------------------------------------------------------
简介下原理:
翻阅源码:
/**
* Casts context to Activity and attempts to create a view reference using the window decor view.
* @return View reference for whole activity.
*/
private View getActivityView() {
Activity activity;
try {
activity = (Activity) getContext();
} catch (ClassCastException e) {
return null;
}
return activity.getWindow().getDecorView().findViewById(android.R.id.content);
}
activity.getWindow().getDecorView().findViewById(android.R.id.content);
通过context强转Activity,通过Activity拿到Window,再Window中获取content
然后剪裁图片,拿到Bitmap后
使用Canvas渲染一个高斯模糊的遮罩层,绘制到这个Bitmap上,最后设置给view
demo:点我去下载页面