在模仿 IOS 密码输入页面的时候发现其背景有模糊处理,于是了解了一下并记录下来,以便使用.在Android 中具体实现方法如下
查考 //www.jb51.net/article/64781.htm

private void applyBlur() {        // 获取壁纸管理器    WallpaperManager wallpaperManager = WallpaperManager.getInstance(this.getContext());    // 获取当前壁纸    Drawable wallpaperDrawable = wallpaperManager.getDrawable();    // 将Drawable,转成Bitmap    Bitmap bmp = ((BitmapDrawable) wallpaperDrawable).getBitmap();       blur(bmp);  }  

下面之所以要进行small 和big的处理,是因为仅仅靠ScriptIntrinsicBlur  来处理模式,不能到达更模式的效果,如果需要加深模式效果就需要先把背景图片缩小,在处理完之后再放大.这个可以使用Matrix 来实现,而且这样可以缩短模糊化得时间

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)  private void blur(Bitmap bkg) {    long startMs = System.currentTimeMillis();    float radius = 20;     bkg = small(bkg);   Bitmap bitmap = bkg.copy(bkg.getConfig(), true);    final RenderScript rs = RenderScript.create(this.getContext());   final Allocation input = Allocation.createFromBitmap(rs, bkg, Allocation.MipmapControl.MIPMAP_NONE,       Allocation.USAGE_SCRIPT);   final Allocation output = Allocation.createTyped(rs, input.getType());   final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));   script.setRadius(radius);   script.setInput(input);   script.forEach(output);   output.copyTo(bitmap);    bitmap = big(bitmap);   setBackground(new BitmapDrawable(getResources(), bitmap));    rs.destroy();    Log.d("zhangle","blur take away:" + (System.currentTimeMillis() - startMs )+ "ms");  }   private static Bitmap big(Bitmap bitmap) {    Matrix matrix = new Matrix();     matrix.postScale(4f,4f); //长和宽放大缩小的比例    Bitmap resizeBmp = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);    return resizeBmp;  }   private static Bitmap small(Bitmap bitmap) {    Matrix matrix = new Matrix();     matrix.postScale(0.25f,0.25f); //长和宽放大缩小的比例    Bitmap resizeBmp = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);    return resizeBmp; } 

更多相关文章

  1. android 图片放大缩小 多点缩放
  2. 关于AES在Android和JAVA上加密解密不能对应的问题
  3. android将ROM改为默认开启调试模式和未知源,默认关闭GPS
  4. 命令模式与Android(安卓)Handler的工作原理
  5. Android:如何将位置信息模式默认设置为高精确度
  6. 简单模拟Android中AlertDialog的Builder设计模式
  7. JobIntentService与IntentService的区别
  8. 【Android(安卓)开发教程】设置Activity的方向
  9. 当 Activity 以全屏模式运行时,如何允许 Android(安卓)系统状态栏

随机推荐

  1. Android之个性化ListView实现
  2. 详解Android客户端与服务器交互方式
  3. 谈Android下一个apk安装多个程序入口图标
  4. Android(安卓)Junit 单元测试、异步测试
  5. Android系统中的ROOT和System权限的区别
  6. 创建Android依赖库-托管JCenter(全过程完
  7. Android(安卓)SQLite
  8. 让Qt应用程序跑在Android上
  9. android开发(46) 使用 textview实现文字
  10. Android源码阅读分析:从Activity开始(二)—