简体   繁体   English

在Android中从内部或外部存储器保存和检索图像

[英]Saving and retrieving images from internal or external memory in android

I want to save the images fetched from server for once and from next time i want to check first whether images are stored or not in device, if not then again it should fetch from server and store in user's device again, and if yes then application will use images directly rather than fetching from server again and again. 我想保存一次从服务器获取的图像,从下一次开始,我想先检查是否在设备中存储了图像,如果不是,则再次从服务器获取并再次存储在用户设备中,如果是,则应用程序将直接使用图片,而不是一次又一次地从服务器获取图片。 It will be useful for enhancing the speed of application. 这对于提高应用速度非常有用。 Basically my application is fetching multiple images from server so i want to save those images on user's android device and from next time application should fetch from device. 基本上我的应用程序正在从服务器获取多个图像,所以我想将这些图像保存在用户的android设备上,并且从下一次应用程序应该从设备获取。 I think you got my question. 我想你有我的问题。

The simple way: 简单的方法:

You can use Picasso. 您可以使用毕加索。 It is a simple lib which provides image downloading and caching. 这是一个简单的库,提供图像下载和缓存。 In my opinion it might not be the fastest, but it is pretty simple and intuitive. 我认为这可能不是最快的方法,但它非常简单直观。 It does its job well and none who I asked complained about it. 它做得很好,我没有问过有人抱怨过它。

Picasso 毕加索

Other libs: 其他库:

UIL UIL

Volley 齐射

Glide 滑行

fresco 壁画

To make it short. 简而言之。 There are lots of other libs. 还有很多其他的库。 An awesome comparision of the most Populat ones can be found here and here 可以在这里这里找到大多数Populat的真棒比较


The do it yourself way: 自己做的方式:

You can also write you own caching logic with a LRUCache. 您还可以使用LRUCache编写自己的缓存逻辑。 Which is also pretty simple. 这也很简单。

Take a look at: 看一眼:

https://developer.android.com/topic/performance/graphics/cache-bitmap.html https://developer.android.com/topic/performance/graphics/cache-bitmap.html

The LRUCache is just a Memory Cache so you might also want to use a DiskLRUCache LRUCache只是一个内存缓存,因此您可能还想使用DiskLRUCache

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM