Android專案實戰(五十七):Glide 高斯模糊效果
核心需要高斯模糊的庫
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) // 設定高斯模糊,模糊程度(最大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)); } }
相關文章
- Android:簡單靠譜的動態高斯模糊效果Android
- Android 圖片高斯模糊解決方案Android
- Flutter BackdropFilter 實現高斯模糊FlutterFilter
- 直播平臺原始碼,用CSS製作毛玻璃效果(高斯模糊效果)原始碼CSS
- Android MVP模式專案實戰AndroidMVP模式
- 後處理 - 高斯模糊
- Android知識問答與分享專案實戰Android
- Android專案實戰之高仿網易雲音樂專案介紹Android
- Android專案實戰之高仿網易雲音樂建立專案和配置Android
- Android安全防護的「多工視窗中的介面高斯模糊處理」其實是個騙局?Android
- dubbo專案實戰
- HarmonyOS 實戰專案
- LittleFox專案實戰
- python實戰專案Python
- Flutter學習 ---- 螢幕截圖和高斯模糊Flutter
- Flutter學習 —- 螢幕截圖和高斯模糊Flutter
- Android專案實戰(四十):Andoird7.0+安裝APK適配AndroidAPK
- TypeScript + 大型專案實戰TypeScript
- AMP專案實戰分享
- Android框架之Volley與GlideAndroid框架IDE
- 現有Android專案中整合Flutter/Flutter混合開發實戰(一)AndroidFlutter
- Android專案實戰之高仿網易雲音樂啟動介面Android
- Android:跟著實戰專案學快取策略之LruCache詳談Android快取
- Android:跟著實戰專案學快取策略之DiskLruCache詳談Android快取
- 這可能是實現高斯模糊(毛玻璃)最簡單的庫了
- Flutter專案實戰(1):通用專案框架搭建Flutter框架
- 安卓Glide(4.7.1)使用筆記 01 - 引入專案安卓IDE筆記
- 巧用模糊實現視覺的 3D 效果視覺3D
- 專案實戰之gradle在實際專案中的使用Gradle
- 淺談 Angular 專案實戰Angular
- 爬蟲實戰專案集合爬蟲
- 專案實戰小問題:
- Jenkins部署Python專案實戰JenkinsPython
- Vue專案實戰(一)——ToDoListVue
- 快速搭建gulp專案實戰
- 爬蟲專案實戰(一)爬蟲
- flask 專案開發實戰Flask
- Sentry - X專案 - 落地實戰