public class GlideBitmapFetcher implements IBitmapFetcher {
private Context mContext;
public GlideBitmapFetcher(Context context) {
mContext = context;
}
@Override
public Bitmap fetchBitmapByFilePath(String path) {
Bitmap bmp = null;
try {
bmp = Glide.with(mContext).asBitmap().load(path).submit().get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
return bmp;
}
@Override
public Bitmap fetchBitmapByUrl(String url) {
Bitmap bmp = null;
try {
bmp = Glide.with(mContext).asBitmap().load(url).submit().get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
return bmp;
}
@Override
public Bitmap fetchBitmapByBase64(String encoded) {
byte[] decode;
encoded = encoded.split(",")[1];
decode = Base64.decode(encoded, Base64.DEFAULT);
Bitmap bmp = null;
try {
bmp = Glide.with(mContext).asBitmap().load(decode).submit().get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
return bmp;
}
}
glide获取bitmap(url,file,base64)
Glide图片加载器实现
最新推荐文章于 2025-09-26 01:19:46 发布
本文介绍了一个使用Glide库实现的图片加载器类,该类可以由文件路径、URL和Base64编码字符串加载图片到Bitmap。通过Glide的强大功能,这个类提供了灵活的图片加载解决方案。
901

被折叠的 条评论
为什么被折叠?



