zocada

Best image loading libraries for android analyzed

Working with images is one of the unavoidable parts of android application development. Maybe it’s from the local storage or from the internet, loading images into views need to be efficient so as fewer resources are being used. From retrieving image contents from the web to caching them for delightful user experience, android image loading libraries come in handy to make the job easier. In this post, we’ll take a look some of the most common and the best android libraries that can be used to load images faster and efficiently.

1. Glide

Glide takes the no. 1 spot among the image loading libraries available today and is the goto library when it comes to image caching and other cool features this library provides. Glide is an open source project developed by BumpTech and is currently at is v4 release. From the GitHub page we can see the description as.

Glide is a fast and efficient image loading library for Android focused on smooth scrolling. Glide offers an easy to use API, a performant and extensible resource decoding pipeline and automatic resource pooling.

bumptech/glide

Glide wins the heart with it’s easy to use API and powerful one liners which helps in doing more in a single line of code.

Glide.with(fragment)
    .load(url)
    .into(imageView)

To use Glide, simply add the following lines of code into the dependencies of your app level build.gradle file.

dependencies {
  implementation ("com.github.bumptech.glide:glide:4.8.0") {
    exclude group: "com.android.support"
  }
  implementation "com.android.support:support-fragment:26.1.0"
}

Glide provides additional features of cropping the image while loading into an ImageView and is one of the few libraries which supports loading GIFs into ImageViews. Here’s a quick example on how to use Glide to load an image with the circular crop. You can learn more about Glide and it’s all other features from it’s official docs.

RequestOptions options = new RequestOptions();
options.centerCrop();

Glide.with(fragment)
    .load(url)
    .apply(options)
    .into(imageView);



2. Picasso

Picasso is also one of the most popular libraries out there which is known for the speed and great caching abilities in android. Picasso is open source and is developed by Square Inc, a company known for it’s awesome contributions to the Android community. Picasso automatically handles image recycling and download cancellation when used with recycler adapters, and makes complex transformations possible with lower memory footprint. One benefit over Glide would be the smaller library size which makes Picasso extremely light weight.

You can easily add Picasso into your project by simply adding the following lines into your build.gradle file.

implementation 'com.squareup.picasso:picasso:2.71828'

You can now start using Picasso in your application by a simple syntax to load image into ImageViews.

Picasso.get()
    .load(url)
    .into(imageView);

Picasso also supports using placeholders for images, while they are loading and when any error occurs during loading of the provided image. You can learn more about Picasso from the official docs of Picasso by Square.

Picasso.get()
    .load(url)
    .placeholder(R.drawable.user_placeholder)
    .error(R.drawable.user_placeholder_error)
    .into(imageView);



3. Fresco

This powerful library developed by the good folks at Facebook is a full-fledged image loading library with great features. Fresco supports out of the box image loading with variable placeholders and it also supports streaming of progressive JPEGs, display of animated GIFs and WebPs, extensive customization of image loading and display and many more. One of the great features of Fresco is that it uses both Main memory and storage memory for caching which increases the performance of the application.

To use Fresco in your project, simply add the following dependecy into your app level build.gradle file.

implementation 'com.facebook.fresco:fresco:1.11.0'

Unlike the other libraries mentioned above, Fresco needs to be initialized once from the Application class of your project.

// MyApplication.java
public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Fresco.initialize(this);
    }
}

Since all the features provided by this library comes in a large library size, to leverage the full benefit of the library we need to use the SimpleDraweeView class item in the View of your layout. As the official API docs of the library suggest…


And then in the Java file associated to the layout, we can easily load the image using the following code.

Uri uri = Uri.parse(url);
SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.my_image_view);
draweeView.setImageURI(uri);

For more details on Fresco and how to use all the rich features it offers, visit the official docs.



Conclusion

While Glide and Fresco provides really fast image loading compared to Picasso. These libraries are really large in size compared to the tiny size of Picasso. Glide comes packed with all the necessary features and it’s easy extend-ability to create custom loaders easily helps it have an upper hand from Fresco. Glide has a fairly simple syntax and API structure while Fresco’s API might seem to be of extra work and confusing. All the above mentioned libraries comes with built in support for WebP images, where as only Glide seems to have an out of the box performance when working with animated images and GIFs.


Also published on Medium.

haxzie

Community Lead with a demonstrated history of working in a non-profit organization. Skilled in Python, Public Speaking, Graphic Design, Writing, and Android Development. Strong community and social services professional with a Bachelor's degree focused in Computer Science from Sahyadri College of Engineering and Management.