重磅消息!Android与IOS的合体!高仿IOS动态高斯模糊背景!

今天无聊逛GaytHub时,无意发现了一个开源库

看下官方的示例图:

这个库是所有Android实现高斯模糊效率最高的方式,底层使用了RenderScript进行图片了算法。

下面是我做的Demo:
重磅消息!Android与IOS的合体!高仿IOS动态高斯模糊背景!_第1张图片

---------------------------------------------------------

重磅消息!Android与IOS的合体!高仿IOS动态高斯模糊背景!_第2张图片

简介下原理:

翻阅源码:

 /**
     * 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:点我去下载页面

你可能感兴趣的:(Android,Android开发从精通到进阶)