真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Android項目實戰(zhàn)之Glide高斯模糊效果的實例代碼

核心需要高斯模糊的庫

創(chuàng)新互聯(lián)秉承實現(xiàn)全網(wǎng)價值營銷的理念,以專業(yè)定制企業(yè)官網(wǎng),成都做網(wǎng)站、成都網(wǎng)站建設(shè),微信小程序開發(fā),網(wǎng)頁設(shè)計制作,手機網(wǎng)站制作,營銷型網(wǎng)站幫助傳統(tǒng)企業(yè)實現(xiàn)“互聯(lián)網(wǎng)+”轉(zhuǎn)型升級專業(yè)定制企業(yè)官網(wǎng),公司注重人才、技術(shù)和管理,匯聚了一批優(yōu)秀的互聯(lián)網(wǎng)技術(shù)人才,對客戶都以感恩的心態(tài)奉獻自己的專業(yè)和所長。

compile 'jp.wasabeef:glide-transformations:2.0.1'

針對于3.7的版本

使用方法為:

//加載背景,
      Glide.with(MusicPlayerActivity.this)
          .load(service.getImageUri())
          .dontAnimate()
          .error(R.drawable.no_music_rotate_img)
          // 設(shè)置高斯模糊,模糊程度(最大25) 縮放比例
          .bitmapTransform(new BlurTransformation(this, 14, 3))
          .into(allBg);

針對4.+

Glide.with(context)
        .load(url)
        .apply(RequestOptions.bitmapTransform(new BlurTransformation(25,8)))
        .into(view);            

BlurTransformation 類源碼:

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
import java.security.MessageDigest;
import jp.wasabeef.glide.transformations.internal.FastBlur;
public class BlurTransformation extends BitmapTransformation {
  private static final int VERSION = 1;
  private static final String ID = "BlurTransformation." + VERSION;
  private static int MAX_RADIUS = 25;
  private static int DEFAULT_DOWN_SAMPLING = 1;
  private int radius;
  private int sampling;
  public BlurTransformation() {
    this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
  }
  public BlurTransformation(int radius) {
    this(radius, DEFAULT_DOWN_SAMPLING);
  }
  public BlurTransformation(int radius, int sampling) {
    this.radius = radius;
    this.sampling = sampling;
  }
  @Override
  protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
    int width = toTransform.getWidth();
    int height = toTransform.getHeight();
    int scaledWidth = width / sampling;
    int scaledHeight = height / sampling;
    Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.scale(1 / (float) sampling, 1 / (float) sampling);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(toTransform, 0, 0, paint);
    bitmap = FastBlur.blur(bitmap, radius, true);
    return bitmap;
  }
  @Override public String toString() {
    return "BlurTransformation(radius=" + radius + ", sampling=" + sampling + ")";
  }
  @Override public boolean equals(Object o) {
    return o instanceof BlurTransformation &&
        ((BlurTransformation) o).radius == radius &&
        ((BlurTransformation) o).sampling == sampling;
  }
  @Override public int hashCode() {
    return ID.hashCode() + radius * 1000 + sampling * 10;
  }
  @Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
    messageDigest.update((ID + radius + sampling).getBytes(CHARSET));
  }
}

總結(jié)

以上所述是小編給大家介紹的Android項目實戰(zhàn)之Glide 高斯模糊效果的實例代碼,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復大家的!


網(wǎng)頁名稱:Android項目實戰(zhàn)之Glide高斯模糊效果的實例代碼
網(wǎng)站URL:http://weahome.cn/article/pdpecs.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部