91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

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

發布時間:2020-09-12 18:34:24 來源:腳本之家 閱讀:178 作者:KevinSpaces 欄目:移動開發

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

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>

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

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

苏尼特左旗| 西林县| 共和县| 武强县| 天长市| 南汇区| 新竹市| 思茅市| 林州市| 额尔古纳市| 沂源县| 阜康市| 宜章县| 临城县| 宾川县| 无锡市| 平塘县| 讷河市| 禹城市| 台北县| 沛县| 平顶山市| 阿勒泰市| 上高县| 贵港市| 西吉县| 河东区| 廉江市| 资源县| 奉节县| 富源县| 自贡市| 丰城市| 西乌珠穆沁旗| 邳州市| 如东县| 精河县| 仁化县| 汝阳县| 广宗县| 广安市|