Jetpack Compose: Image loading using Coil

Abhishek Pundir
Geek Culture
Published in
2 min readAug 10, 2021

--

Coil (Coroutine Image Loader) is a Kotlin-first image loading library for Android which uses Kotlin Coroutines behind the hood.

Why Use Coil?

It is fast, modern, and easy to use.

It simplifies image loading from the internet by automatically handling the network request, image caching, request cancellation, error handling, memory management, and more.

Unlike other image loading libraries, Coil is largely decoupled from Fragments and Views.

  1. Include Dependency

2. Adding Permissions

3. Downloading the image

  • We can use the rememberImagePainter function to create an ImagePainter that can be drawn by the Image composable:
  • ImagePainter manages the asynchronous image request and handles drawing the placeholder/success/error drawables.

Read more about ContentScale.

4. Transformations (Advanced Stuff)

  • Transformations allow us to modify the image before it is returned from the request.
  • Eg: GrayscaleTransformation (converting image to grayscale), CircleCropTransformation (shows the image in circular bounds), BlurTransformation (blurs the whole image), RoundedCornersTransformations (transforms the corners of the image into rounded shapes), and a lot more.

Multiple Transformations Simultaneously.

Summary

So this is the basic info on Coil, if you like it and want to explore more or want to give it a try check out the following link.

Coil Documentation.

Next, we’ll explore some other Jetpack Compose related features.

Till then Happy Composing.

--

--