如何从毕加索的缓存中检索图像? [英] How to retrieve images from cache memory in picasso?

查看:32
本文介绍了如何从毕加索的缓存中检索图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 picasso 库来加载图像.在默认的 picasso 中,它使用内部缓存来加载图像.但根据我的应用程序配置,我必须使用外部缓存(磁盘上的缓存).所以我将此代码用于磁盘缓存

I am using picasso library for loading images .In default picasso, It uses internal cache memory for loading images.But as per my app configuration ,i have to use external cache memory(Cache on Disk). so i used this code for Cache on Disk

              File httpCacheDir = new File(getApplicationContext().getExternalCacheDir(),"http");
                long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
               HttpResponseCache.install(httpCacheDir, httpCacheSize);}

毕加索是灵活的.所以现在它在外部 Sd 卡中缓存图像..

Picasso is flexible. So now it caches images in external Sd card..

缓存存储在 sdcard/android/data/packagename/cache/http缓存存储在.1"、.0"中.格式所以我只是打开它们并更改为.1"到.jpg".它提供了我需要的确切图像.但是如何以编程方式进行呢?但毕加索本身将我的内存缓存到我的应用程序中,以便将图像加载到 imageview 中.但我必须将它们作为图像直接保存到 SD 卡中/在离线模式下将位图设置为墙纸?

The caches is stored in sdcard/android/data/packagename/cache/http The caches are stored in ".1" ,".0". formats so i just opened them and changes into ".1" to ".jpg".it gives exact images what i need. But how to do in programatically? but picasso itself caches my memory in to my app for loading image into imageview.but i have to save them into sdcard directly as images/set bitmap as wallpaper in offline mode?

推荐答案

您可以在构建 Picasso 实例时提供自己的 Cache 实现.通过这种方式,您可以提供额外的方法,您可以调用这些方法直接从内存缓存中检索位图.使用 Picasso.Builder 为其提供您自己的实现.当您使用 with() 时,您使用的是静态单例内部实例,该实例设置了大多数默认值(大多数应用程序无论如何都需要默认值.)

You can supply your own Cache implementation when building your Picasso instance. This way you can provide extra methods that you can call to retrieve bitmaps directly from your memory cache. Use Picasso.Builder to provide your own implementation for it. When you use with() you are using a static singleton internal instance thats setup with most of the default values (most apps need the default values anyway.)

保留对您的 Cache 实现的引用并直接与其交互.Picasso 旨在为您处理加载/解码和缓存,但您没有理由不能围绕它进行构建.

Keep a reference of your Cache implementation around and directly interact with it. Picasso is meant to handle the loading/decoding and caching for you but there is no reason you cant build around it.

如果您指的是磁盘缓存,那么目前没有毕加索不支持.这是设计使然,因为磁盘层缓存是由 HTTP 层完成的,并且没有区别.

If you are referring about the disk cache, then no Picasso does not support that at the moment. This is by design because the disk layer cache is done by the HTTP layer and makes no distinction about it.

但是,您可以更改磁盘缓存的路径.如果您使用 OkHttpDownloader,则在构建下载器时提供不同的文件.同样,对于 UrlConnectionDownloader,您可以扩展它并覆盖 load() 方法.

You could however, change the path of the disk cache. If you are using OkHttpDownloader then supply a different file when you construct your Downloader. Similarly for UrlConnectionDownloader you could extend it and override the load() method.

这篇关于如何从毕加索的缓存中检索图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆