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

首頁 > 系統 > Android > 正文

Android實現圖片轉高斯模糊以及高斯模糊布局

2019-10-22 18:31:05
字體:
來源:轉載
供稿:網友

第一個為大家介紹圖片如何轉高斯模擬:

1.方法的實現:

public static void updateBgToBlur(Activity a, Bitmap bmpToBlur, View view, int resId) {    BitmapFactory.Options opt = new BitmapFactory.Options();    opt.inJustDecodeBounds = true;    opt.inSampleSize = 8;    opt.inJustDecodeBounds = false;    Bitmap bmp = BitmapFactory.decodeResource(a.getResources(), resId, opt);    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {      view.setBackground(null);    } else {      view.setBackgroundDrawable(null);    }    if (bmpToBlur != null && !bmpToBlur.isRecycled()) {      bmpToBlur.recycle();    }    bmpToBlur = blurBitmap(a, bmp);    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {      view.setBackground(new BitmapDrawable(a.getResources(), bmpToBlur));    } else {      view.setBackgroundDrawable(new BitmapDrawable(a.getResources(), bmpToBlur));    }  }  public static Bitmap blurBitmap(Context c, Bitmap bitmap) {    //Let's create an empty bitmap with the same size of the bitmap we want to blur    Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_4444);    //Instantiate a new Renderscript    RenderScript rs = RenderScript.create(c.getApplicationContext());    //Create an Intrinsic Blur Script using the Renderscript    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));    //Create the Allocations (in/out) with the Renderscript and the in/out bitmaps    Allocation allIn = Allocation.createFromBitmap(rs, bitmap);    Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);    //Set the radius of the blur    blurScript.setRadius(25.f);    //Perform the Renderscript    blurScript.setInput(allIn);    blurScript.forEach(allOut);    //Copy the final bitmap created by the out Allocation to the outBitmap    allOut.copyTo(outBitmap);    //recycle the original bitmap    bitmap.recycle();    //After finishing everything, we destroy the Renderscript.    rs.destroy();    return outBitmap;  }

2 調用:

 Bitmap bitmap=null;    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {      ImageUtil.updateBgToBlur(getActivity(), bitmap, slidingUpPanelLayout, R.drawable.bg_tageditor);    } else {      slidingUpPanelLayout.setBackgroundResource(R.drawable.bg_tageditor);    }

二、高斯模糊布局:

項目需求: 現有一個紫色背景圖片, 相冊圖片覆蓋在背景圖片 , 一個Framlayout 覆蓋在這個含有相冊圖片的背景圖中 ,實現模糊蓋在上面的高斯模擬效果:

1 引用BlurView:

 compile 'com.eightbitlab:supportrenderscriptblur:1.0.0' compile 'com.eightbitlab:blurview:1.3.3' defaultConfig {    renderscriptTargetApi 25 //must match target sdk and build tools, 23+    renderscriptSupportModeEnabled true }

2 .調用:

 

final float radius = 20;    final View decorView = getActivity().getWindow().getDecorView();    //Activity's root View. Can also be root View of your layout (preferably)    final ViewGroup rootView = (ViewGroup) decorView.findViewById(android.R.id.content);    //set background, if your root layout doesn't have one    final Drawable windowBackground = decorView.getBackground();    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {      mBlurView.setupWith(rootView)          .windowBackground(windowBackground)          .blurAlgorithm(new RenderScriptBlur(getActivity()))          .blurRadius(radius);    }else {      mBlurView.setupWith(rootView)          .windowBackground(windowBackground)          .blurAlgorithm(new SupportRenderScriptBlur(getActivity()))          .blurRadius(radius);    }

3 xml

 <eightbitlab.com.blurview.BlurView   android:id="@+id/blurView"   android:layout_width="match_parent"   android:layout_height="wrap_content"   app:blurOverlayColor="@color/colorOverlay">    <!--Any child View here, TabLayout for example--> </eightbitlab.com.blurview.BlurView>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 万源市| 平顺县| 莒南县| 江孜县| 蒙山县| 祁门县| 加查县| 平乐县| 调兵山市| 伊通| 疏附县| 尉犁县| 孟村| 永靖县| 海兴县| 连云港市| 寻乌县| 黄陵县| 曲麻莱县| 会泽县| 左贡县| 浮梁县| 泽库县| 久治县| 舟曲县| 石渠县| 海安县| 乌拉特前旗| 达日县| 威远县| 阳春市| 炉霍县| 朝阳县| 肃北| 泸溪县| 敖汉旗| 上饶市| 四平市| 平江县| 大埔县| 蒙山县|