android开发分享Android中实现布局背景模糊化处理的方法

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

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

上述就是android开发分享Android中实现布局背景模糊化处理的方法的全部内容,如果对大家有所用处且需要了解更多关于Android学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

  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;   }   

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/addevelopment/940926.html

(0)
上一篇 2021年11月14日
下一篇 2021年11月14日

精彩推荐