修改图片

This commit is contained in:
18401019693
2022-10-29 13:44:48 +08:00
parent cb118e4a9f
commit 7e9d2917b6
12 changed files with 233 additions and 213 deletions

View File

@@ -2,9 +2,7 @@ package com.yunbao.common.glide;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.text.TextUtils;
import android.widget.ImageView;
@@ -16,7 +14,6 @@ import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.yunbao.common.R;
@@ -29,9 +26,10 @@ import jp.wasabeef.glide.transformations.BlurTransformation;
*/
public class ImgLoader {
private static final boolean SKIP_MEMORY_CACHE = false;
private static final boolean SKIP_MEMORY_CACHE = true;
private static BlurTransformation sBlurTransformation;
private final static float thumbnail = 0.1f;
static {
sBlurTransformation = new BlurTransformation(25);
@@ -47,14 +45,15 @@ public class ImgLoader {
}
RequestBuilder<Drawable> builder = Glide.with(context)
.load(url);
if (width != -1 && height != -1) {
builder = builder.override(width, height);
}
builder.into(imageView);
builder.thumbnail(thumbnail).into(imageView);
}
public static void display2(Context context, String url, ImageView imageView) {
display2(context, url, imageView, -1, -1);
display2(context, url, imageView, 320, 320);
}
/**
@@ -71,6 +70,8 @@ public class ImgLoader {
}
RequestBuilder<Drawable> builder = Glide.with(context)
.load(url)
.thumbnail(thumbnail)
.dontAnimate()
.placeholder(imageView.getDrawable());
if (width != -1 && height != -1) {
@@ -86,6 +87,8 @@ public class ImgLoader {
Glide.with(context)
.asDrawable()
.load(url)
.thumbnail(thumbnail)
.placeholder(imageView.getDrawable())
.dontAnimate()
.skipMemoryCache(SKIP_MEMORY_CACHE)
@@ -106,6 +109,7 @@ public class ImgLoader {
RequestBuilder<Drawable> builder = Glide.with(context)
.load(url)
.thumbnail(thumbnail)
.error(errorRes);
if (width != -1 && height != -1) {
builder = builder.override(width, height);
@@ -120,7 +124,7 @@ public class ImgLoader {
if (imageView == null) {
return;
}
Glide.with(context).asDrawable().load(url).error(errorRes).skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView);
Glide.with(context).asDrawable().load(url).thumbnail(thumbnail).error(errorRes).skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView);
}
public static void displayAvatar(Context context, String url, ImageView imageView) {
@@ -137,6 +141,8 @@ public class ImgLoader {
RequestBuilder<Drawable> builder = Glide.with(context)
.load(url)
.thumbnail(thumbnail)
.error(R.mipmap.icon_avatar_placeholder);
if (width != -1 && height != -1) {
builder = builder.override(width, height);
@@ -159,6 +165,8 @@ public class ImgLoader {
Glide.with(context)
.asDrawable()
.load(file)
.thumbnail(thumbnail)
.skipMemoryCache(SKIP_MEMORY_CACHE)
.into(imageView);
}
@@ -170,6 +178,8 @@ public class ImgLoader {
Glide.with(context)
.asDrawable()
.load(res)
.thumbnail(thumbnail)
.skipMemoryCache(SKIP_MEMORY_CACHE)
.into(imageView);
}
@@ -184,6 +194,7 @@ public class ImgLoader {
Glide.with(context)
.asDrawable()
.load(Uri.fromFile(new File(videoPath)))
.thumbnail(thumbnail)
.skipMemoryCache(SKIP_MEMORY_CACHE)
.into(imageView);
}
@@ -198,6 +209,7 @@ public class ImgLoader {
Glide.with(context)
.asGif()
.load(videoPath)
.thumbnail(thumbnail)
.skipMemoryCache(SKIP_MEMORY_CACHE)
.into(imageView);
}
@@ -208,7 +220,7 @@ public class ImgLoader {
if (callback != null)
callback.onLoadFailed();
} else {
Glide.with(context).asDrawable().load(url).skipMemoryCache(SKIP_MEMORY_CACHE).into(new CustomTarget<Drawable>() {
Glide.with(context).asDrawable().load(url).thumbnail(thumbnail).skipMemoryCache(SKIP_MEMORY_CACHE).into(new CustomTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
@@ -239,7 +251,7 @@ public class ImgLoader {
if (!contextIsExist(context)) {
return;
}
Glide.with(context).asDrawable().load(file).skipMemoryCache(SKIP_MEMORY_CACHE).into(new CustomTarget<Drawable>() {
Glide.with(context).asDrawable().load(file).thumbnail(thumbnail).skipMemoryCache(SKIP_MEMORY_CACHE).into(new CustomTarget<Drawable>() {
@Override
@@ -280,6 +292,7 @@ public class ImgLoader {
RequestBuilder<Drawable> builder = Glide.with(context)
.load(url)
.thumbnail(thumbnail)
.apply(RequestOptions.bitmapTransform(sBlurTransformation));
if (width != -1 && height != -1) {
builder = builder.override(width, height);
@@ -300,6 +313,7 @@ public class ImgLoader {
}
RequestBuilder<Drawable> builder = Glide.with(context)
.load(url)
.thumbnail(thumbnail)
.apply(RequestOptions.bitmapTransform(new BlurTransformation(20)))
.placeholder(R.mipmap.live_bg);
if (width != -1 && height != -1) {