Los*_*ppy 5 android image-caching android-image picasso
有没有办法通过指定使用的缓存键将图像加载到Picasso的图像缓存中?
如果不可能,请注意,我已做了必要的更改,但我不确定如何重建jar.任何重建毕加索的指示都非常感谢.
小智 5
您可以在 requestCreator 对象上调用 stableKey。
它会像:
Picasso.with(context).load(yourURL).stableKey(yourKey).into(textView);
我没有发现没有公开访问此功能,但对我来说,可以使用此解决方法:
//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);
Run Code Online (Sandbox Code Playgroud)
请注意,密钥用于 uri 和您的自定义转换(调整大小、centerCrop ant 等,请参阅 com.squareup.picasso.Utils#createKey)