Local image caching solution for Android: Square Picasso vs Universal Image Loader

Local image caching solution for Android: Square Picasso vs Universal Image Loader

http://stackoverflow.com/questions/19995007/local-image-caching-solution-for-android-square-picasso-vs-universal-image-load图片缓存库使用对比

question

I need async image loading and caching in Android. Anyone knows about these two libraries? I was going to use Picasso, but I found Universal Image Loader is more popular on Github. A summary of pros and cons would be great.(All my images are on disk locally, so I don‘t need networking, I don‘t think Volley is a fit)

Answers

If you read this post on G+ by Koush you will get clear solutions for your confusions, I have put the summary of that, in that Android-Universal-Image-Loader is the winner for your requirement!

  • Picasso has the nicest image API if you are using network!
  • UrlImageViewHelper + AndroidAsync is the fastest. Playing with these other two great libraries have really highlighted that the image API is quite dated, however.
  • Volley is slick; I really enjoy their pluggable backend transports,and may end up dropping AndroidAsync in there. The request priorityand cancellation management is great(if you are using network)
  • Android-Universal-Image-Loader is the most popular one out therecurrently. Highly customizable.

This project aims to provide a reusable instrument for asynchronous image loading, caching and displaying. It is originally based on Fedor Vlasov‘s project and has been vastly refactored and improved since then.

Upcoming changes in new UIL version (1.9.2):

Possibility to call ImageLoader out of UI threadNew Disk Cache API (more flexible). New LruDiscCache based on Jake Wharton‘s DiskLruCache.

Considering all this Android-Universal-Image-Loader suites your requirement (Loading the images are on disk locally)!

----------

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.

Picasso:

  • 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 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.
  • 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 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...).
  • 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 only has a few simple examples on the homepage, and you‘ll have to read through the unordered javadoc for advanced usages.

UIL:

  • UIL uses builders for customization. Almost everything can be configured.
  • 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. (Edit: this behavior can be easily modified by adding an ImageSize argument in in the source code and bypass the view size checking)
  • 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. (Edit: 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 by default caches images of different sizes in memory, and it can be turned off in configuration.
  • UIL exposes the backing memory and disk cache you can access.
  • UIL provides flexible ways you can get a bitmap or load to a view.
  • UIL is better in documentation. UIL gives the detailed usages on the Github page, and there‘s a linked tutorial.

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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。