欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用Glide實(shí)現(xiàn)高斯模糊效果

 更新時(shí)間:2020年12月17日 11:16:41   作者:春機(jī)復(fù)燃  
這篇文章主要為大家詳細(xì)介紹了使用Glide實(shí)現(xiàn)高斯模糊效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

使用Glide實(shí)現(xiàn)高斯模糊效果,供大家參考,具體內(nèi)容如下

先來(lái)看效果

第一步:引入依賴

implementation 'com.github.bumptech.glide:glide:4.7.1'
implementation 'jp.wasabeef:glide-transformations:2.0.1'

第二步:自定義繼承自BitmapTransformation的類

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Build;
import android.renderscript.RSRuntimeException;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;

import java.nio.charset.Charset;
import java.security.MessageDigest;

import jp.wasabeef.glide.transformations.internal.FastBlur;
import jp.wasabeef.glide.transformations.internal.RSBlur;


/**
 * 虛化Transformation
 * 更多效果參考:https://github.com/wasabeef/glide-transformations
 */

public class BlurTransformation extends BitmapTransformation {

  private static String STRING_CHARSET_NAME = "UTF-8";
  private static final String ID = "com.kevin.glidetest.BlurTransformation";
  private static Charset CHARSET = Charset.forName(STRING_CHARSET_NAME);
  private static final byte[] ID_BYTES = ID.getBytes(CHARSET);

  private static int MAX_RADIUS = 25;
  private static int DEFAULT_DOWN_SAMPLING = 1;

  private Context mContext;
  private BitmapPool mBitmapPool;

  private int mRadius;
  private int mSampling;

  public BlurTransformation(Context context) {
    this(context, Glide.get(context).getBitmapPool(), MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
  }

  public BlurTransformation(Context context, BitmapPool pool) {
    this(context, pool, MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
  }

  public BlurTransformation(Context context, BitmapPool pool, int radius) {
    this(context, pool, radius, DEFAULT_DOWN_SAMPLING);
  }

  public BlurTransformation(Context context, int radius) {
    this(context, Glide.get(context).getBitmapPool(), radius, DEFAULT_DOWN_SAMPLING);
  }

  public BlurTransformation(Context context, int radius, int sampling) {
    this(context, Glide.get(context).getBitmapPool(), radius, sampling);
  }

  public BlurTransformation(Context context, BitmapPool pool, int radius, int sampling) {
    mContext = context.getApplicationContext();
    mBitmapPool = pool;
    mRadius = radius;
    mSampling = sampling;
  }


  @Override
  protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int
      outWidth, int outHeight) {
    Bitmap source = toTransform ;

    int width = source.getWidth();
    int height = source.getHeight();
    int scaledWidth = width / mSampling;
    int scaledHeight = height / mSampling;

    Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
    if (bitmap == null) {
      bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(bitmap);
    canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(source, 0, 0, paint);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
      try {
        bitmap = RSBlur.blur(mContext, bitmap, mRadius);
      } catch (RSRuntimeException e) {
        bitmap = FastBlur.blur(bitmap, mRadius, true);
      }
    } else {
      bitmap = FastBlur.blur(bitmap, mRadius, true);
    }

    //return BitmapResource.obtain(bitmap, mBitmapPool);
    return bitmap;
  }

  @Override
  public int hashCode() {
    return ID.hashCode();
  }

  @Override
  public boolean equals(Object obj) {
    return obj instanceof BlurTransformation;
  }

  @Override
  public void updateDiskCacheKey(MessageDigest messageDigest) {
    messageDigest.update(ID_BYTES);
  }

}

第三步:實(shí)際使用

String url="url";
 Glide.with(this).load(url)
 .apply(RequestOptions.bitmapTransform(new BlurTransformation(this,25,3)))
        .into(img);
 //參數(shù)用來(lái)設(shè)置模糊程度

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • android自定義Dialog彈框和背景陰影顯示效果

    android自定義Dialog彈框和背景陰影顯示效果

    這篇文章主要為大家詳細(xì)介紹了android自定義Dialog彈框和背景陰影顯示效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • Android視頻錄制功能的實(shí)現(xiàn)步驟

    Android視頻錄制功能的實(shí)現(xiàn)步驟

    這篇文章主要介紹了Android視頻錄制功能的實(shí)現(xiàn)步驟,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • Android ADB簡(jiǎn)介、安裝及使用詳解

    Android ADB簡(jiǎn)介、安裝及使用詳解

    ADB 全稱為 Android Debug Bridge,起到調(diào)試橋的作用,是一個(gè)客戶端-服務(wù)器端程序,其中客戶端是用來(lái)操作的電腦,服務(wù)端是 Android 設(shè)備,這篇文章介紹Android ADB簡(jiǎn)介、安裝及使用,感興趣的朋友跟隨小編一起看看吧
    2024-01-01
  • Android實(shí)現(xiàn)掃碼功能

    Android實(shí)現(xiàn)掃碼功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)掃碼功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-05-05
  • Android控件設(shè)置寬高比的方法

    Android控件設(shè)置寬高比的方法

    本篇文章主要介紹了Android控件設(shè)置寬高比的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-02-02
  • Android仿支付寶的頭部伸縮動(dòng)畫效果

    Android仿支付寶的頭部伸縮動(dòng)畫效果

    Android5.0推出的MaterialDesign庫(kù)包含了處理頭部工具欄的多個(gè)控件,不但允許自定義頂部導(dǎo)航欄,而且導(dǎo)航欄高度是可以伸縮的。下文給大家介紹Android仿支付寶的頭部伸縮動(dòng)畫效果,需要的朋友參考下吧
    2017-05-05
  • android開(kāi)發(fā)教程之自定義控件checkbox的樣式示例

    android開(kāi)發(fā)教程之自定義控件checkbox的樣式示例

    這篇文章主要介紹了android自定義checkbox的樣式示例,需要的朋友可以參考下
    2014-03-03
  • Android數(shù)據(jù)加密之異或加密算法的實(shí)現(xiàn)方法

    Android數(shù)據(jù)加密之異或加密算法的實(shí)現(xiàn)方法

    下面小編就為大家?guī)?lái)一篇Android數(shù)據(jù)加密之異或加密算法的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-10-10
  • Android實(shí)現(xiàn)彈出登陸框的方案

    Android實(shí)現(xiàn)彈出登陸框的方案

    最近在做一個(gè)項(xiàng)目,要用到登陸框,幾經(jīng)波折,最后用的是直接將Activity的Theme屬性設(shè)置成Dialog,然后達(dá)到了我想要的效果。
    2014-07-07
  • Flutter 滾動(dòng)監(jiān)聽(tīng)及實(shí)戰(zhàn)appBar滾動(dòng)漸變的實(shí)現(xiàn)

    Flutter 滾動(dòng)監(jiān)聽(tīng)及實(shí)戰(zhàn)appBar滾動(dòng)漸變的實(shí)現(xiàn)

    這篇文章主要介紹了Flutter 滾動(dòng)監(jiān)聽(tīng)及實(shí)戰(zhàn)appBar滾動(dòng)漸變,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09

最新評(píng)論