Android中實現(xiàn)布局背景模糊化處理的方法
在模仿 IOS 密碼輸入頁面的時候發(fā)現(xiàn)其背景有模糊處理,于是了解了一下并記錄下來,以便使用.在Android 中具體實現(xiàn)方法如下
查考 http://m.fzitv.net/article/64781.htm
private void applyBlur() {
// 獲取壁紙管理器
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this.getContext());
// 獲取當(dāng)前壁紙
Drawable wallpaperDrawable = wallpaperManager.getDrawable();
// 將Drawable,轉(zhuǎn)成Bitmap
Bitmap bmp = ((BitmapDrawable) wallpaperDrawable).getBitmap();
blur(bmp);
}
下面之所以要進(jìn)行small 和big的處理,是因為僅僅靠ScriptIntrinsicBlur 來處理模式,不能到達(dá)更模式的效果,如果需要加深模式效果就需要先把背景圖片縮小,在處理完之后再放大.這個可以使用Matrix 來實現(xiàn),而且這樣可以縮短模糊化得時間
@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;
}
- Android實現(xiàn)本地上傳圖片并設(shè)置為圓形頭像
- Android使用CircleImageView實現(xiàn)圓形頭像的方法
- Android Studio實現(xiàn)帶邊框的圓形頭像
- Android一行代碼實現(xiàn)圓形頭像
- Android圓形頭像拍照后“無法加載此圖片”的問題解決方法(適配Android7.0)
- Android 自定義圓形頭像CircleImageView支持加載網(wǎng)絡(luò)圖片的實現(xiàn)代碼
- android dialog背景模糊化效果實現(xiàn)方法
- Android實現(xiàn)個人資料頁面頭像背景模糊顯示包(狀態(tài)欄)
- Android實現(xiàn)用戶圓形頭像和模糊背景
相關(guān)文章
Android 基于Socket的聊天應(yīng)用實例(二)
本篇文章主要介紹了Android 基于Socket的聊天應(yīng)用實例,具有一定的參考價值,有需要的可以了解一下。2016-12-12
android實用工具類分享(獲取內(nèi)存/檢查網(wǎng)絡(luò)/屏幕高度/手機(jī)分辨率)
這篇文章主要介紹了android實用工具類,包括獲取內(nèi)存、檢查網(wǎng)絡(luò)、屏幕高度、手機(jī)分辨率、獲取版本號等功能,需要的朋友可以參考下2014-03-03
Android使用系統(tǒng)相機(jī)進(jìn)行拍照的步驟
這篇文章主要介紹了Android使用系統(tǒng)相機(jī)進(jìn)行拍照的步驟,幫助大家更好的進(jìn)行Android開發(fā),感興趣的朋友可以了解下2020-12-12
Android studio 3.0 查看手機(jī)文件系統(tǒng)的方法(超簡單)
本文給大家分享Android studio更新到3.0版本之后,查看手機(jī)文件系統(tǒng)的方法,需要的朋友參考下吧2017-11-11
Android 四種動畫效果的調(diào)用實現(xiàn)代碼
在這里, 我將每種動畫分別應(yīng)用于四個按鈕為例,需要的朋友可以參考下2013-01-01
Android 跨進(jìn)程SharedPreferences異常詳解
這篇文章主要介紹了Android 跨進(jìn)程SharedPreferences異常詳解的相關(guān)資料,需要的朋友可以參考下2017-05-05

