Android 本地图像缓存解决方案:Square Picasso、Universal Image Loader、Glide、Fresco? [英] Local image caching solution for Android: Square Picasso, Universal Image Loader, Glide, Fresco?

查看:19
本文介绍了Android 本地图像缓存解决方案:Square Picasso、Universal Image Loader、Glide、Fresco?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个在 Android 中的异步图像加载和缓存库.我打算使用 Picasso,但我发现 Universal Image Loader 在 GitHub 上更受欢迎.有谁知道这两个图书馆?利弊的总结会很棒.

I am looking for an asynchronous image loading and caching library in Android. I was going to use Picasso, but I found Universal Image Loader is more popular on GitHub. Does anyone know about these two libraries? A summary of pros and cons would be great.

(我所有的图片都在本地磁盘上,所以我不需要联网,因此我认为 Volley 不合适)

(All my images are on disk locally, so I don't need networking, therefore I don't think Volley is a fit)

推荐答案

2018 年 9 月更新:几年后,我需要一个几乎相同的本地图像缓存解决方案.这一次,UIL 并未处于积极开发阶段.我比较了流行的库,得出的结论很简单:只需使用 Glide.它更强大,更可配置.几年前,我不得不分叉并更改 UIL.Glide 在缓存策略和使用自定义键的多级分辨率缓存方面支持我的所有用例.只需使用 Glide!

Update Sep 2018: After several years, I needed the almost same thing for a local image caching solution. This time around, UIL has not been in active development. I compared the popular libraries, and the conclusion is pretty no-brainer: just use Glide. It's much more powerful and configurable. Years ago I had to fork and make changes to UIL. Glide supports all my use cases in terms of caching strategy and multiple levels of resolution caching with custom keys. Just use Glide!

Koushik Dutta 的比较主要是针对速度基准.他的帖子只涉及非常基本的东西,并不针对本地图像.在我提出问题后,我想分享一下我与毕加索和 UIL 的经历.Picasso 和 UIL 都可以加载本地图像.我第一次尝试 Picasso 并很高兴,但后来我决定改用 UIL 以获得更多自定义选项.

Koushik Dutta's comparison is mostly for speed benchmark. His post only touched very basic things, and is not specific for local images. I'd like to share my experiences with Picasso and UIL after I asked the question. Both Picasso and UIL can load local images. I first tried Picasso and was happy, but later I decided to switch to UIL for more customization options.

毕加索:

  • 毕加索的流畅界面很好.但是用with"、into"、load"来跳来跳去,你实际上不知道幕后是什么.返回的内容令人困惑.

  • Picasso's fluent interface is nice. But jumping around with "with", "into", "load" you actually don't know what's behind the scene. It's confusing what's returned.

Picasso 允许您指定准确的目标尺寸.当您遇到内存压力或性能问题时,它很有用,您可以牺牲一些图像质量来换取速度.

Picasso allows you to specify exact target size. It's useful when you have memory pressure or performance issues, you can trade off some image quality for speed.

图像缓存在其键中的大小,这在您显示不同大小的图像时很有用.

Images are cached with size in its key, it's useful when you display images with different sizes.

您可以自定义内存缓存大小.但它的磁盘缓存仅用于 http 请求.对于本地图片,如果您关心加载速度,最好有一个缩略图磁盘缓存,这样您就不必每次都读取几 MB 的图片.Picasso 没有这种在磁盘上调整缩略图大小和保存缩略图的机制.

You can customize the memory cache size. But its disc cache is only for http requests. For local images, if you care about loading speed, it's good to have a thumbnail disk cache so you don't have to read several MBs for an image every time. Picasso does not have this mechanism resizing and saving thumbnails on disk.

Picasso 不会公开对其缓存实例的访问权限.(当您第一次配置毕加索并保留它时,您可以掌握它......).

Picasso does not expose the access to its cache instance. (You can get a hold of it when you first configure Picasso and keep it around...).

有时您希望将图像异步读取到侦听器返回的位图中.令人惊讶的是,毕加索没有那个.fetch()"不会传回任何东西.get()"用于同步读取,load()"用于异步绘制视图.

Sometimes you want to asynchronously read image into a bitmap returned by a listener. Surprisingly Picasso doesn't have that. "fetch()" dose not pass back anything. "get()" is for synchronously read, and "load()" is for asynchronously draw a view.

Picasso 主页上只有几个简单的示例,您必须通读无序的 javadoc 以了解高级用法.

Picasso only has a few simple examples on the homepage, and you'll have to read through the unordered javadoc for advanced usages.

UIL:

  • UIL 使用构建器进行定制.几乎所有东西都可以配置.

  • UIL uses builders for customization. Almost everything can be configured.

UIL 不允许您指定要加载到视图中的大小.它根据视图的大小使用一些规则.它不像毕加索那样灵活.我无法加载较低分辨率的图像来减少内存占用.(可以通过在源代码中添加 ImageSize 参数并绕过视图大小检查来轻松修改此行为)

UIL does not allow you to specify the size you want to load into a view. It uses some rules based on the size of the view. It's not as flexible as Picasso. I have no way to load a lower resolution image to reduce memory footprint. ( this behavior can be easily modified by adding an ImageSize argument in in the source code and bypass the view size checking)

UIL 提供可自定义的光盘缓存,您可以使用它来缓存指定大小的缩略图.但它并不完美.以下是详情.(如果你关心速度并想要多级缩略图缓存,就像我的情况,你可以修改源代码,让磁盘缓存使用memoryKey",并使其对大小敏感)

UIL provides customizable disc cache, you can use this to cache the thumbnails with specified size. But it's not perfect. Here are the details. ( if you care about speed and want multiple levels of thumbnail caching, like my case, you can modify the source code, let the disk cache use "memoryKey", and make it also size sensitive)

UIL 默认在内存中缓存不同大小的图片,可以在配置中关闭.

UIL by default caches images of different sizes in memory, and it can be turned off in configuration.

UIL 公开您可以访问的后备内存和磁盘缓存.

UIL exposes the backing memory and disk cache you can access.

UIL 提供了获取位图或加载到视图的灵活方式.

UIL provides flexible ways you can get a bitmap or load to a view.

UIL 在文档方面更好.UIL 在 Github 页面上给出了详细的用法,并且有一个链接教程.

UIL is better in documentation. UIL gives the detailed usages on the Github page, and there's a linked tutorial.

我建议从 Picasso 开始,如果您需要更多控制和自定义,请选择 UIL.

I suggest starting with Picasso, if you need more control and customization, go for UIL.

这篇关于Android 本地图像缓存解决方案:Square Picasso、Universal Image Loader、Glide、Fresco?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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