69 lines
2.1 KiB
Java
69 lines
2.1 KiB
Java
package com.sw.st.net;
|
|
|
|
import android.content.Context;
|
|
import android.widget.ImageView;
|
|
|
|
import com.bumptech.glide.Glide;
|
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
|
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
|
import com.bumptech.glide.request.FutureTarget;
|
|
import com.bumptech.glide.request.RequestOptions;
|
|
import com.sw.st.R;
|
|
|
|
import java.io.File;
|
|
|
|
/**
|
|
* 图片加载管理
|
|
*/
|
|
public class ImageLoaderManager {
|
|
public static void LoadRoundImage(Context context, String imgUrl, ImageView imageView, int roundingRadius) {
|
|
RequestOptions cropOptions = new RequestOptions();
|
|
cropOptions.transform(new RoundedCorners(roundingRadius));//new CenterCrop()
|
|
|
|
Glide.with(context)
|
|
.load(imgUrl)
|
|
.placeholder(R.mipmap.ic_launcher)
|
|
.dontAnimate() //解决圆形图显示占位图问题
|
|
.error(R.mipmap.ic_launcher)
|
|
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
|
.apply(cropOptions)
|
|
.into(imageView);
|
|
}
|
|
|
|
public static void LoadImage(Context context, String imgUrl, ImageView imageView) {
|
|
|
|
Glide.with(context)
|
|
.load(imgUrl)
|
|
.placeholder(R.mipmap.ic_launcher)
|
|
.dontAnimate() //解决圆形图显示占位图问题
|
|
.error(R.mipmap.ic_launcher)
|
|
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
|
.into(imageView);
|
|
|
|
// Glide
|
|
// .with(myFragment)
|
|
// .load(url)
|
|
// .centerCrop()
|
|
// .placeholder(R.drawable.loading_spinner)
|
|
// .into(myImageView);
|
|
}
|
|
|
|
|
|
/**
|
|
* 缓存图片到本地
|
|
*/
|
|
public static File CacheFile(Context context, String imgUrl) {
|
|
File cacheFile = null;
|
|
FutureTarget<File> future = Glide.with(context)
|
|
.load(imgUrl)
|
|
.downloadOnly(500, 500);
|
|
try {
|
|
cacheFile = future.get();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return cacheFile;
|
|
}
|
|
|
|
}
|