Picasso – Image caching Library in Android

Android Picasso Tutorial

In this post, I am going to discuss what Picasso library is and how to use it?

Picasso is open source image downloading and caching library for Android. It is developed and maintained by Square. If we compare with other image caching libraries, the Picasso library is very powerful one.

Advantage of using Picasso library

We have to think about three things for displaying the image.

  1. Network usage
  2. Memory usage
  3. Disk usage/ storage

This library will handle above matter very properly and efficiently. We don’t need to worry about it.

If you want to display server side images on Android app by writing your own code that will be difficult and want to write many lines of code from scratch. But if you use Picasso, you can display the image with couple of lines.

If you write your own code to display the image then you want to properly manage the UI thread otherwise app will crash.  But Picasso will handle this thread procedure.

It will handle multiple downloads at once.

Run time we can scale and fit the image to the view.

Other image caching libraries for Android

  1. Universal Image Loader
  2. Glide
  3. Volley

I will discuss above libraries in my future post.

Now we will see how to use this Picasso. Normally you all know how to create project and import the library. Anyway I will show, how to import the library to our demo project.

Right click on your project then select Open Module Settings

Open Android project settings

Now you can see below Project Structure wizard (To open this Project structure window select the project and Click F4 key)

Picasso demo project structure wizard

Select dependencies tab and click on the green color plus (+) button select Library Dependency

Now search as Picasso and hope you can see the result list. Select the second one com.squareup.picasso package one click OK.

Android picasso library search

Now automatically Gradle will build itself.

So now we have done the configuration. Let see how to use this Picasso and display remote server image in imageview.

I am going to display the image using above imageview before that I need to add internet permission in manifest file.

First initialize the imagview variable and set the image url to imageview to display using Picasso. Now you may think, until download the image you want to show a default image or if there is any image loading issue then want to show error message image. How to handle it? Yah Picasso has a solution.

Default / error image handling

Runtime resize or rotate the image

Yes, using the Picasso you can resize and rotate the image.

Welcome to LearnLinky.com

LearnLinky Happy Reading

 

Hope this article help you to understand how to use Picasso on Android app. don’t forget to put your comments or suggestions.

 

Add Comment