我正在使用UniversalImageDownloader
作为我的app.in UIL我们可以保存来自缓存的图像。
File cachedImage = ImageLoader.getInstance().getDiscCache().get(imageUrl);
if (cachedImage.exists())
{// code for save 2 sd
}
毕加索有可能吗?
答案 0 :(得分:1)
毕加索有一个私人方法 -
Bitmap quickMemoryCacheCheck(String key) {
Bitmap cached = cache.get(key);
if (cached != null) {
stats.dispatchCacheHit();
} else {
stats.dispatchCacheMiss();
}
return cached;
}
根据您的需要修改来源。
答案 1 :(得分:1)
你可以这样做,使用OkHttp&毕加索:
public class APP extends Application{
public static OkHttpDownloader okHttpDownloader;
@Override
public void onCreate() {
super.onCreate();
Picasso.Builder b = new Picasso.Builder(this);
okHttpDownloader = new OkHttpDownloader(this);
b.downloader(okHttpDownloader);
Picasso.setSingletonInstance(b.build());
}
}
然后从OkHttp本地缓存中获取文件:
Downloader.Response res = APP.okHttpDownloader.load(Uri.parse(your image Url),0);
Log.i(TAG,"Get From DISK: " + res.isCached() );
storeImageFile(res.getInputStream());
答案 2 :(得分:0)
您可以从ImangeView onSuccess()回调
获取位图Picasso.with(context).load(path).into(imageView, new Callback(){
public void onSuccess() {
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
//save bitmap to sdcard
}
public void onError() {}
}
警告:保存的位图可能与原始位图不同。
答案 3 :(得分:0)
下面的代码片段首先会让Picasso从缓存中加载图片,如果失败则会在imageView中下载并显示图片
您可以使用
调试内存性能Picasso.with(appContext).setIndicatorsEnabled(真);
红色(网络,性能最差)。
//Debugging memory performance https://futurestud.io/tutorials/picasso-cache-indicators-logging-stats
//TODO remove on deployment
Picasso.with(appContext).setIndicatorsEnabled(true);
//Try to load image from cache
Picasso.with(appContext)
.load(imageUrl)
.networkPolicy(NetworkPolicy.OFFLINE).placeholder(R.drawable.ic_launcher)
.placeholder(R.drawable.ic_launcher)
.resize(100, 100)
.error(R.drawable.ic_drawer)
.into(markerImageView, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
// Try online if cache failed
Picasso.with(appContext)
.load(imageUrl)
.placeholder(R.drawable.ic_launcher)
.resize(100, 100)
.error(R.drawable.ic_drawer)
.into(markerImageView);
}
});