标签:href 老师 api文档 ado view dcl col cal 注意
今天主要研究了Glide获取图片Path、Bitmap用法,相信也困扰了大家很久,我在网上也找了很久,基本没有,后来研究了下,也参考了下api文档,总结了以下几个方式:
1. 获取Bitmap:
1)在图片下载缓存好之后获取
Glide.with(mContext).load(url).asBitmap().into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
image.setImageBitmap(resource);
}
}); //方法中设置asBitmap可以设置回调类型
Glide.with(mContext).load(url).asBitmap().into(new Target<Bitmap>() {
@Override
public void onLoadStarted(Drawable placeholder) {
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
}
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
//TODO set bitmap
}
@Override
public void onLoadCleared(Drawable placeholder) {
}
@Override
public void getSize(SizeReadyCallback cb) {
}
@Override
public void setRequest(Request request) {
}
@Override
public Request getRequest() {
return null;
}
@Override
public void onStart() {
}
@Override
public void onStop() {
}
@Override
public void onDestroy() {
}
});
2)通过url获取
Bitmap myBitmap = Glide.with(applicationContext)
.load(yourUrl)
.asBitmap() //必须
.centerCrop()
.into(500, 500)
.get()
FutureTarget<File> future = Glide.with(mContext)
.load("url")
.downloadOnly(500, 500);
try {
File cacheFile = future.get();
String path = cacheFile.getAbsolutePath();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
来自:http://blog.csdn.net/qq_19711823/article/details/50856236
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow
Android之Glide获取图片Path和Glide获取图片Bitmap
标签:href 老师 api文档 ado view dcl col cal 注意
原文地址:https://www.cnblogs.com/skiwnchhw/p/10349282.html