国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android中實現布局背景模糊化處理的方法

2020-04-11 11:36:02
字體:
來源:轉載
供稿:網友

在模仿 IOS 密碼輸入頁面的時候發現其背景有模糊處理,于是了解了一下并記錄下來,以便使用.在Android 中具體實現方法如下
查考 //m.survivalescaperooms.com/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; } 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 迁安市| 双流县| 竹溪县| 灵宝市| 蕉岭县| 邯郸县| 阿坝| 永新县| 原阳县| 侯马市| 西平县| 家居| 商城县| 西宁市| 财经| 贵南县| 丹凤县| 玛沁县| 江油市| 永顺县| 泰顺县| 台湾省| 临沧市| 云浮市| 富锦市| 大关县| 栖霞市| 山东| 黄浦区| 贵南县| 格尔木市| 南乐县| 茂名市| 米脂县| 大悟县| 聂荣县| 广宁县| 常熟市| 谢通门县| 济南市| 探索|