Glide Image Loader Library in Android

Ayush Soni
2 min readOct 26, 2022

--

Like Picasso, Glide is able to load and show pictures from a variety of sources while also managing caching and maintaining a minimal memory footprint when doing image editing. Glide is used by official Google applications, such as the Google I/O 2015 app. In this post, we’ll examine Glide’s features and the reasons it excels in some areas.

How to use Glide Library?

  1. To use glide in your project you have to add glide dependence in gradle file.Open the app/build.gradle file in the app folder of your Android project and add the following lines there to add the dependency. And sync the project.
dependencies {implementation ‘com.github.bumptech.glide:glide:4.11.0’annotationProcessor ‘com.github.bumptech.glide:compiler:4.11.0’}

2. Now add InternetPermission inside the AndroidManifest.xml file.

<uses-permission android:name=”android.permission.INTERNET”/>

3. Now add a imageView in layout.

<ImageViewandroid:layout_width=”wrap_content”android:layout_height=”wrap_content”android:id=”@+id/imageView”android:layout_alignParentTop=”true”android:layout_centerHorizontal=”true” />

4. Now use this following code block to laod image url.

ImageView imageView = (ImageView) findViewById(R.id.imageView);Glide.with(context).load(“YOUR IMAGE URL HERE”).into(imageView).error(R.drawable.imagenotfound);

Advanced Features of Glide

  1. Resize : In this case, we are retrieving a distant picture using Glide and altering (resizing) it before presenting it in an image view.
Glide.with(context).load(“YOUR IMAGE URL HERE”).override(400, 300).error(R.drawable.imagenotfound).into(imageView);

2. Placeholder : Add a fallback in the form of a placeholder picture if your application depends on distant assets. When Glide has completed retrieving the distant picture, it replaces the placeholder image that was displayed earlier.

Glide.with(context).load(“YOUR IMAGE URL HERE”).placeholder(R.drawable.placeholder).into(imageView);

3. Handling errors : Additionally, there is an error function that takes a replacement picture. If Glide is unable in retrieving the remote asset, it will make three attempts to download the remote picture and then show the error placeholder image.

Glide.with(context).load(“YOUR IMAGE URL HERE”).placeholder(R.drawable.placeholder).error(R.drawable.imagenotfound).into(imageView);

4. Rounded Corners :

int radius = 40;int margin = 10;Glide.with(context).load(“YOUR IMAGE URL HERE”).bitmapTransform(new RoundedCornersTransformation(context, radius, margin)).into(imageView);

5.Circle crop :

Glide.with(context).load(“YOUR IMAGE URL HERE”).bitmapTransform(new CropCircleTransformation(context)).into(imageView);

6. Blur image:

Glide.with(context).load(“YOUR IMAGE URL HERE”).bitmapTransform(new BlurTransformation(context)).into(imageView);

7. Multiple Transform:

Glide.with(context).load(“YOUR IMAGE URL HERE”).bitmapTransform(new BlurTransformation(context, 25), new CropCircleTransformation(context)).into(imageView);

8. Gif

Glide.with(context)
.asGif()
.load(urlGif)
.into(imageView)

Thank you, and I hope this was helpful. Bye-bye

--

--