How to load, process and cache image in Android using Glide

In this tutorial you can read about Glide. The advanced library for image uploading, caching, rotating and small memory usage.

Android SDK does not have a good way to get images from web and display it to android app. To solve this problem, numbers of third party libraries are available.

  • Picasso
  • Glide
  • Fresco
  • UImageLoader

You can read some comparison here and here.

Glide features

  • supports thumbnail
  • supports animations
  • animated GIF decoding, you can load GIF animation into ImageView
  • supports OkHttp and Volley library
  • display video stills
  • placeholder can be added before loading the original image
  • any custom image can be shown if error occurs while loading the original image

Glide offers some additional advantages over other image loading libraries. For example, when loading an image, Glide will cache both a version of the image in its original size as well as one that’s the size of its intended ImageView. This means Glide loads the image noticeably faster than libraries like Picasso because no resize is necessary. Additionally, Glide works with Android’s ImageView (Facebook’s Fresco uses DraweeView and Volley uses NetworkImageView).

Getting started with Glide is as easy as using Picasso. Their API also look quite similar.

Add the Gradle dependency to your android module build.gradle. Glide also needs android support library v4. Also I'm going to use CircleImageView for circle effect for image.

dependencies {
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile ''
    compile 'de.hdodenhof:circleimageview:2.1.0'

The way to load an image to ImageView with Glide is quite the same as Picasso.


Although it looks quite the same but in details Glide is designed far better since with doesn't accept only Context but also Activity and Fragment. The brilliant benefit from passing Activity/Fragment to Glide is: image loading would be integrated with Activity/Fragment's lifecycle for example, pause loading in Paused state and automatically resume on Resumed state.

The way Glide loads an image to memory and do the caching is better than Picasso which let an image loaded far faster. In addition, it also helps preventing an app from popular OutOfMemoryError. You can read more about memory usage here.

Load image from server server


Loading image from res/drawable folder


Show placeholder image


Transform image

   .override(200, 200)

Fade on load


Let's build simple application that will demonstrates Glide usage

Layout file

<?xml version="1.0" encoding="utf-8"?>


In MainActivity file define variable for ImageView and set image URL for load method of Glide. Following is the complete code of java activity file.

public class MainActivity extends AppCompatActivity {
    CircleImageView img;
    String url = "";

    protected void onCreate(Bundle savedInstanceState) {

        img = (CircleImageView) findViewById(;



We can use transformations for crop, blur, color, mask.

Bitmap format

Glide’s default bitmap format is set to RGB_565 so image quality will be poorer compared with Picasso. But the advantage is that it will consume less memory. If you are ok with image quality, don’t change the bitmap format else change it to ARGB_8888 as below.

public class GlideConfiguration implements GlideModule {
    public void applyOptions(Context context, GlideBuilder builder) {
    public void registerComponents(Context context, Glide glide) {
        // register ModelLoaders here.

Then, add meta-tag into AndroidManifest.xml

<meta-data android:name="com.example.proft.GlideConfiguration"

If you run the app, images will look better now.

Image caching

Glide creates cached images per size while Picasso saves the full image and process it. If you are trying to load image (500x500) into ImageView (200x200). Glide will download full image, then resize it to 200x200, then it will cache and load into ImageView while Picasso will download full image then it will cache full image then resize it to 200x200 and load it into ImageView.

Next time when you request same image (500x500) to load into ImageView (100x100), Glide will again download the full image (500x500) then resize it to 100x100 then cache and load into ImageView. Picasso, unlike Glide, picks up the cached full size image and resize and load it into ImageView (100x100). Picasso doesn’t download same image again.

However, you can configure Glide to cache full size and resized image as below.


Useful links

comments powered by Disqus