Local image caching solution for Android: Square Picasso, Universal Image Loader, Glide, Fresco?
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'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.
Error while loading image with Glide, Picasso , Coli , Fresco
you can check out this sample: https://github.com/bumptech/glide/blob/master/samples/svg/src/main/java/com/bumptech/glide/samples/svg/MainActivity.java
Which provides better Image Loading/Caching - Volley or Picasso?
volley' Request class deal with all network requests. I have not yet found any class loading resource from disk..
How To Use universal image loader offline caching?
You can use the ImageLoaderConfiguration.Builder
class to customize disk caching. This includes the methods:
diskCacheExtraOptions()
diskCacheSize()
(in bytes).diskCacheFileCount()
diskCacheFileNameGenerator()
- and some others.
Or you can just use diskCache(DiskCache)
to provide a custom class for implementing offline caching.
From the example in the Configuration section of the wiki:
File cacheDir = StorageUtils.getCacheDirectory(context);
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.memoryCacheExtraOptions(480, 800) // default = device screen dimensions
.diskCacheExtraOptions(480, 800, null)
.taskExecutor(...)
.taskExecutorForCachedImages(...)
.threadPoolSize(3) // default
.threadPriority(Thread.NORM_PRIORITY - 1) // default
.tasksProcessingOrder(QueueProcessingType.FIFO) // default
.denyCacheImageMultipleSizesInMemory()
.memoryCache(new LruMemoryCache(2 * 1024 * 1024))
.memoryCacheSize(2 * 1024 * 1024)
.memoryCacheSizePercentage(13) // default
.diskCache(new UnlimitedDiscCache(cacheDir)) // default
.diskCacheSize(50 * 1024 * 1024)
.diskCacheFileCount(100)
.diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
.imageDownloader(new BaseImageDownloader(context)) // default
.imageDecoder(new BaseImageDecoder()) // default
.defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
.writeDebugLogs()
.build();
Does Glide, Picasso or other image loading library affects app's performance when loading image from local resources in RecyclerView?
If your images are stored in the drawable
directories and you already have different sizes for different resolutions, then using another library for loading those images would not add much benefit.
However, if you have your images in raw
or you don't have different sizes, just big ones, using something like Glide turns out to be quite useful, since it will resize down the image to fit the required space and stores the smaller image in the cache (memory or disk, depending on how you configure it). This considerably speeds up subsequent loads since the android UI doesn't need to do the scaling again.
Comparison of Image Library for Android (Picasso, Fresco, etc.)
Refer to this:
https://twitter.com/jessewilson/status/581235604740042752
Local image caching solution for Android: Square Picasso vs Universal Image Loader
https://www.bignerdranch.com/blog/solving-the-android-image-loading-problem-volley-vs-picasso/
Android Image loading - Volley vs Picasso
Picasso v/s Imageloader v/s Fresco vs Glide
Related Topics
How to Install Android Sdk Build Tools on the Command Line
Android - Get Children Inside a View
Android - Webview Language Changes Abruptly on Android 7.0 and Above
How to Programmatically Add Buttons into Layout One by One in Several Lines
Use Uri Builder in Android or Create Url with Variables
How to Get a Working Vertical Seekbar in Android
Get the Uri of an Image Stored in Drawable
Execution Failed for Task ':App:Compiledebugaidl': Aidl Is Missing
Android and Setting Width and Height Programmatically in Dp Units
How to Generate Class Diagram (Uml) on Android Studio (Intellij Idea)
How to Size an Android View Based on Its Parent's Dimensions
Firebase (Fcm): Open Activity and Pass Data on Notification Click. Android
How to Globally Force Screen Orientation in Android
Why Do I Get Access Denied to Data Folder When Using Adb