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

查考 http://www.cnblogs.com/lipeil/p/3997992.html

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 5.1拍照后图片镜像处理
  2. Android工作总结之如何做一个优秀的MediaPlayer音频播放器
  3. Androd学习笔记——Android中Touch事件的处理逻辑
  4. android中视频播放的处理
  5. Android对返回键进行处理的方式
  6. Android(安卓)Service
  7. Android(安卓)手势
  8. 探索 Android(安卓)平台的 CameraX
  9. Android开发之消息处理机制(二)——消息循环

随机推荐

  1. 填坑总结:通过selector的android:state_ch
  2. Android高手进阶教程(三)之----Android(
  3. Android事件分发机制及如何解决事件冲突
  4. 一年学习总结和分享android广告赚钱
  5. android style(样式)和theme(主题)设置
  6. Android(安卓)多线程-----AsyncTask详解
  7. Android(安卓)主题之安装的APK主题文件
  8. Facebook Buck和xctool:针对Android和iOS
  9. html5 canvas android bug
  10. Android入门教程(五)之------第一个Andro