最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android中實(shí)現(xiàn)布局背景模糊化處理的方法

 更新時(shí)間:2015年04月24日 10:06:53   投稿:junjie  
這篇文章主要介紹了Android中實(shí)現(xiàn)布局背景模糊化處理的方法,需要的朋友可以參考下

在模仿 IOS 密碼輸入頁面的時(shí)候發(fā)現(xiàn)其背景有模糊處理,于是了解了一下并記錄下來,以便使用.在Android 中具體實(shí)現(xiàn)方法如下
查考 http://www.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的處理,是因?yàn)閮H僅靠ScriptIntrinsicBlur  來處理模式,不能到達(dá)更模式的效果,如果需要加深模式效果就需要先把背景圖片縮小,在處理完之后再放大.這個(gè)可以使用Matrix 來實(shí)現(xiàn),而且這樣可以縮短模糊化得時(shí)間

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

相關(guān)文章

最新評(píng)論

麟游县| 永兴县| 凤冈县| 澎湖县| 镇江市| 乌兰浩特市| 景德镇市| 陆川县| 日照市| 米易县| 凤山县| 南京市| 阳山县| 临洮县| 漠河县| 邵武市| 西城区| 长葛市| 西青区| 柘城县| 海丰县| 调兵山市| 巴南区| 锡林浩特市| 历史| 黔东| 马边| 修文县| 溆浦县| 扎赉特旗| 芮城县| 宁武县| 门源| 阿瓦提县| 信阳市| 深州市| 龙州县| 岫岩| 南靖县| 安仁县| 饶平县|