Why, When, Where to use Glide?

Rakesh
Bobble Engineering
4 min readOct 6, 2020

--

What is Glide?

Glide is an Image Loader Library for Android developed by bumptech and is a library that is recommended by Google. It has been used in many Google open source projects including Google I/O 2014 official application. It provides animated GIF support and handles image loading/caching. It’s easy to use and requires minimal configuration. Using glide library we can show image, decode images, cache images, animated gifs and many more.

Why Glide?

In Android, working with images(bitmaps) is really difficult as the application goes out of memory(OOM) very frequently. OOM is the biggest nightmare for Android developers. We face Issues like

  • Large-size images often require a good deal of memory to process, which can cause “out-of-memory” (OOM) errors and app crashes.
  • Images that are received or processed slowly cause a “laggy” experience for the user. Most users don’t have much patience for these performance hits.
  • Processing images for display in a much smaller screen area than the original image also requires an inordinate amount of CPU cycles, which can cause apps to slow down or stop altogether while the CPU tries to get through the intense processing demands.
  • Depending on the processing algorithm used, the processed image may suffer from changes in color, sharpness, brightness, and contrast.
  • All of these problems are magnified in the case of animated images, because each one is a series of static images.

To ease our pain we have many open Image Loading Libraries Like

  • Glide — : Glide is very fast and has a very good caching mechanism. Perhaps the best caching mechanism among all image loading libraries. It allows to specify size of image for view. It will add 440 Kb and 2678 methods to your code. It allows Loading a frame from video as a picture and GIF, using any type of model, it also offers a flexible API with the ability to connect any network stack. Using Glide is as simple as below -
//One Line Loading
Glide.with(fragment).load(url).into(imageView)
//Loading with Request Options
RequestOptions options = new RequestOptions();
options.centerCrop();

Glide.with(fragment).load(url).apply(options).into(imageView);
  • Fresco — : Native Library so large size will add more than 500KBs, it is tedious to use and not easy like Picasso or Glide, It does not uses ImageView instead it uses SimpleDraweeView (a custom view that extends ImageView) which makes multiple things easier like transforming in xml layout itself. However, it does not cache images of different sizes. It features Saving images not in Java Heap, but in ashmem heap, the ability to crop images around any point, resize JPEG using native resources, support for Progressive JPEG images. Unlike the other libraries mentioned above, Fresco needs to be initialized once from the Application class of your project, so your application needs to be started atleast once before you can load. Using Fresco is a bit tricky as shown below -
// MyApplication.java
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Fresco.initialize(this);
}
}

Layout XML File —

<com.facebook.drawee.view.simpledraweeview android:id="@+id/my_image_view" android:layout_width="130dp" android:layout_height="130dp" fresco:placeholderimage="@drawable/my_drawable">
</com.facebook.drawee.view.simpledraweeview>

Code —

Uri uri = Uri.parse(url);
SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.my_image_view);
draweeView.setImageURI(uri);
  • Picasso — : very simple to use and smallest in size (121Kbs ),It allows to specify size for view but does not cache images in different sizes, The downside is it uses large memory to load images and hence I have seen a lot of OOMs with it. I would not recommend using it if you have to load a large number of high resolution images. Like Glide Picasso using Picasso is also pretty Simple
//Picasso One Line loading
Picasso.get().load(url).into(imageView);
// Picasso Loading with options
Picasso.get().load(url).placeholder(R.drawable.user_placeholder)
.error(R.drawable.user_placeholder_error)
.into(imageView);
  • Universal Image Loader — : UIL is quite tedious and ugly to use, But, it is highly configurable and uses minimum memory to load images and is small in size(157KB). One of the downside is it does not allow you to specify the size you want to load into a view. Project support has stopped since 27.11.2015

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, loading times are faster and it uses a small amount of memory for cache.

When and Where to use Glide?

As we have seen, each library have got its own advantages and disadvantages, If your application uses few Images, and you dont need any transformations, then picasso is way to go. Similarly if your application is heavily dependent on the images, Image quality if your top concern, and you have very experienced developers, and you are OK with a little extra size in your build, Fresco will do the job.

Glide is best of both worlds. It is really easy to use and is lightening fast. you can specify the size of image you want to cache, you can configure the quality of the image, and it provides features of both picasso and fresco. It got small cache size, supports GIF, WebP, Bitmap Pool etc. If you want to add image functionality to existing project Glide or Picasso is best bet. Glide’s primary focus is on making scrolling any kind of a list of images as smooth and fast as possible, but Glide is also effective for almost any case where you need to fetch, resize, and display a remote image.

--

--