如何在再次保存之前检查图像是否已经在内存中?
How do I check if the images are already in the memory before they are saved again?
我注意到在优化我的应用程序性能时,Glide 必须检查图像是否已在缓存中。现在问题来了。
它是如何工作的?
使用下面的代码,我总是会在课程开始时再次保存图像并加载。
所以:
Glide.with(mContext).load(Objects.requireNonNull(user).getImageurl()).donloadOnly(new SimpleTarget <File>(){
@Override
public void onResourceReady(File resource, GlideAnimation<? super File> glideAnimation){
OGGER.debug("Photo downloaded");
}
});
Glide.with(mContext).load(Objects.requireNonNull(user).getImageurl()).diskCacheStrategy(DiskCacheStrategy.SOURCE).into(image_profile);
或:
Glide.with(mContext).load(Objects.requireNonNull(user).getImageurl()).donloadOnly(new SimpleTarget <File>(){
@Override
public void onResourceReady(File resource, GlideAnimation<? super File> glideAnimation){
OGGER.debug("Photo downloaded");
Glide.with(mContext).load(Objects.requireNonNull(user).getImageurl()).diskCacheStrategy(DiskCacheStrategy.SOURCE).into(image_profile);
}
});
谢谢。 :)
正如他们在文档中提到的那样:
默认情况下,Glide 在开始对图像的新请求之前检查多层缓存:
- 活动资源 - 此图像现在是否显示在另一个视图中?
- 内存缓存 - 此图像是最近加载的并且仍在内存中吗?
- 资源 - 此图像之前是否被解码、转换并写入磁盘缓存?
- 数据-这张图片的数据是之前写入磁盘缓存的吗?
强烈推荐您阅读。
https://bumptech.github.io/glide/doc/caching.html#caching-in-glide
要将图像加载到 ivImg
(您的 ImageView)中,您只需执行以下操作:
Glide.with(context)
.load("http://via.placeholder.com/300.png")
.into(ivImg);
我注意到在优化我的应用程序性能时,Glide 必须检查图像是否已在缓存中。现在问题来了。
它是如何工作的?
使用下面的代码,我总是会在课程开始时再次保存图像并加载。
所以:
Glide.with(mContext).load(Objects.requireNonNull(user).getImageurl()).donloadOnly(new SimpleTarget <File>(){
@Override
public void onResourceReady(File resource, GlideAnimation<? super File> glideAnimation){
OGGER.debug("Photo downloaded");
}
});
Glide.with(mContext).load(Objects.requireNonNull(user).getImageurl()).diskCacheStrategy(DiskCacheStrategy.SOURCE).into(image_profile);
或:
Glide.with(mContext).load(Objects.requireNonNull(user).getImageurl()).donloadOnly(new SimpleTarget <File>(){
@Override
public void onResourceReady(File resource, GlideAnimation<? super File> glideAnimation){
OGGER.debug("Photo downloaded");
Glide.with(mContext).load(Objects.requireNonNull(user).getImageurl()).diskCacheStrategy(DiskCacheStrategy.SOURCE).into(image_profile);
}
});
谢谢。 :)
正如他们在文档中提到的那样:
默认情况下,Glide 在开始对图像的新请求之前检查多层缓存:
- 活动资源 - 此图像现在是否显示在另一个视图中?
- 内存缓存 - 此图像是最近加载的并且仍在内存中吗?
- 资源 - 此图像之前是否被解码、转换并写入磁盘缓存?
- 数据-这张图片的数据是之前写入磁盘缓存的吗?
强烈推荐您阅读。 https://bumptech.github.io/glide/doc/caching.html#caching-in-glide
要将图像加载到 ivImg
(您的 ImageView)中,您只需执行以下操作:
Glide.with(context)
.load("http://via.placeholder.com/300.png")
.into(ivImg);