【问题标题】:Store images in picasso with a cache key of our own使用我们自己的缓存键将图像存储在 picasso
【发布时间】:2014-09-15 03:46:25
【问题描述】:

有没有一种方法可以通过指定使用的缓存键将图像加载到毕加索的图像缓存中?

附带说明,如果这是不可能的,我已经进行了必要的更改,但我不确定如何重建 jar。任何重建毕加索的指示都非常感谢。

【问题讨论】:

  • 这似乎是一个非常合乎逻辑的问题。我想知道为什么它没有答案!

标签: android android-image picasso image-caching


【解决方案1】:

您可以在您的 requestCreator 对象上调用 stableKey。

https://square.github.io/picasso/2.x/picasso/com/squareup/picasso/RequestCreator.html#stableKey-java.lang.String-

它会像: Picasso.with(context).load(yourURL).stableKey(yourKey).into(textView);

【讨论】:

    【解决方案2】:

    我没有发现对此功能没有公开访问权限,但对我来说可以使用此解决方法:

    //1. Init picasso, create cache
    mCache = new LruCache(mContext);
    mPicasso = new Picasso.Builder(mContext).memoryCache(mCache).build();
    
    //2. Load bitmap 
    mPicasso.load(uri).resize(mThumbWidth, mThumbHeight).centerCrop().into(v, callback);
    
    //3. In case of error (for example, in callback), you can manually download the picture and store to cache
    Bitmap bmp = <custom load>
    //make key
    StringBuilder sb = new StringBuilder(uri);
    sb.append("\nresize:").append(mThumbWidth).append("x").append(mThumbHeight).append("\ncenterCrop\n");
    mCache.set(sb.toString(), bmp);
    

    请注意,键用于 uri 和您的自定义转换(resize、centerCrop ant 等,请参阅 com.squareup.picasso.Utils#createKey 了解更多信息)

    【讨论】:

      【解决方案3】:

      这对我有用

      String strUrl = WWW.sultan.com....;    
          Bitmap = bitmap;
          Picasso.with(Profile.this).load(strUrl).into(new Target() {
              @Override
              public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                  userImage.setImageBitmap(bitmap);
                  this.bitmap = bitmap; //this can be used any where in the code   
      
              }
      
              @Override
              public void onBitmapFailed(Drawable errorDrawable) {
      
              }
      
              @Override
              public void onPrepareLoad(Drawable placeHolderDrawable) {
      
              }
          });
      

      【讨论】:

        猜你喜欢
        • 2019-11-04
        • 1970-01-01
        • 2014-09-23
        • 2012-01-16
        • 2023-03-13
        • 2015-06-13
        • 2015-11-25
        • 2016-09-03
        • 1970-01-01
        相关资源
        最近更新 更多