Picasso Android Tutorial – Load Image from URL

In this tutorial you will learn how to use Picasso android library to load image from url.

Picasso is an open source android library which is developed and maintained by Square. Below are some features that make this library the best option for loading image from internet.

Features

  • Easy to use and reduces the code very much
  • Automatic memory and cache management
  • Allows image transformation

You can also use Volley library, which is a great alternative of Picasso.

Also Read: Android Volley Tutorial

Picasso Android Tutorial – Load Image from URL

Picasso Android Tutorial

Before using Picasso we have to add its dependency in build.gradle file.

 

Also add internet access permission in AndroidMainfest.xml file.

 

Loading Image

We can load image by just typing one line of code. It can be done in following way.

 

Place Holder and Error Handler

We can specify an image as a place holder until the image is being loaded. We can also give an image as an error handler if any error occurs while loading the image.

 

Image Transformation

As I already told that this library also supports image transformation. So we can change image dimensions to fit layouts and reduce memory size.

 

Don’t you thing that it reduces the code very much?

 

Picasso Android Example

In this example I am loading image from url on button click.

Create a project with package name com.picassoandroid and add following code in respective files

activity_main.xml

 

MainActivity.java

 

The code is self explanatory, if still you are facing any difficulty in above Picasso android tutorial then feel free to ask it by commenting below.

Happy Coding!! 🙂 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *