gpt4 book ai didi

java - 在再次保存图像之前如何检查图像是否已经在内存中?

转载 作者:行者123 更新时间:2023-12-02 05:22:20 24 4
gpt4 key购买 nike

我注意到在优化应用程序的性能时,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 在开始新的图像请求之前会检查多层缓存:

  1. Activity 资源 - 该图像现在是否显示在另一个 View 中?
  2. 内存缓存 - 该图像是最近加载的并且仍在内存中吗?
  3. 资源 - 此图像之前是否已被解码、转换并写入磁盘缓存?
  4. 数据 - 获取该图像的数据之前是否已写入磁盘缓存?

我强烈建议您阅读它。 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);

关于java - 在再次保存图像之前如何检查图像是否已经在内存中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56251535/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com