【问题标题】:How to make an image always in memory Picasso如何使图像始终在记忆中毕加索
【发布时间】:2018-08-23 06:22:11
【问题描述】:

我刚刚开始在 Android 中使用 Picasso,但我意识到当 Picasso 加载太多图像时会导致内存不足,之前加载的图像将从内存中删除,所以当我回来时Picasso 将再次从 Internet 加载。我只是想让一些重要的图像永远留在记忆中,比如 Profile Picture。 我应该将图像存储在磁盘内存中还是使用其他库或其他东西。有人可以指导我解决方案吗?

【问题讨论】:

  • 是的,我已经检查过了,我试过了,但它不起作用
  • 我不知道 Picasso 在做什么,但例如 Glide 也在使用磁盘缓存来存储它加载的图像。
  • 尝试使用 glide 加载图像。它有两级缓存磁盘缓存和内存缓存。如果内存缓存中没有值,图像将从内存缓存中加载,这意味着它将从磁盘缓存中加载。

标签: android picasso


【解决方案1】:

您可以Glide满足您的要求,它是一个强大的图片加载库

在您的应用程序 gradle 中执行此操作

repositories {
  mavenCentral()
  google()
}

dependencies {
  implementation 'com.github.bumptech.glide:glide:4.8.0'
  annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
}

用法:-

Glide.with(context)
                .load(url_here)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(holder.imageView);

这是缓存所有版本图像的密钥DiskCacheStrategy.ALL

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-05
    • 2015-10-16
    • 2020-11-14
    • 1970-01-01
    • 2020-08-30
    相关资源
    最近更新 更多