毕加索没有预取图像

时间:2015-10-08 21:16:58

标签: android caching picasso

我使用Picasso预取图像并且没有被缓存。电话是:

在之前的活动中,我有:

Picasso.with(this)
  .load(uri)
  .fetch();

在接下来的活动中我有:

Picasso.with(this)
  .load(uri)
  .fit()
  .centerInside()
  .placeholder(R.drawable.placeholder)
  .error(R.drawable.error)
  .into(profileImage, null);

可能发生什么事?

1 个答案:

答案 0 :(得分:1)

我有同样的问题,几周前,问题是,当您使用此代码获取图像时:

    Picasso.with(this)
      .load(uri)
      .fetch();

Picasso使用url作为密钥将图像保存在缓存中(原始图像保存在磁盘/ ram中),但是当您尝试使用.into()方法显示图像时,生成的密钥毕加索它实际上是不同的,因为它包含了它将保存下载图像的imageView的大小。因此,如果您想真正放入缓存所需的确切图像,则必须在提取调用中包含resize方法(此大小必须与您的imageView相同),例如

    Picasso.with(context).load(imageUrl)
    .resize(targetWidth,targetHeight)
    .fetch();