Picasso : Image Loading Library for Android tutorial

An Image Loader Library for Android developed by Square named Picasso as a library .Picasso is an open source media management framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface. Picasso supports fetching, decoding, and displaying images. Picasso includes a flexible API that allows developers to plug in to almost any network stack.

Picasso’s primary focus is on making scrolling any kind of a list of images as smooth and fast as possible, but Picasso is also effective for almost any case where you need to fetch, resize, and display a remote image.

Picasso Features

Picasso version 2.5.2 supports large number of features
-Automatic memory and disk caching
-Thumbnail support
-Image Transformation
-Resource Loading

Why to use ?

– It simplifies the process of loading images from external urls and display on your application. For example, downloading an image from server, is one of the most common task in any application. And it needs quite a larger amount of code to achieve this via android networking API’s. By using Picasso, you can achieve this with few lines of code.
– It is always not about downloading image from remote location. You also have to think of implementing image caching logic in order to provide a seamless user experience. Picasso provides automatic image caching.
– Image transformation is a costly affair. If your application need deal with such runtime image transformation, you must be watchful about OutOfMemoryException. Picasso deals with it, so you dont have to do it yourself.

Picasso Usage in Android

In this tutorials i will show you how to use Picasso in android project . following are the steps .

Step 1 ) Update build.gradle file

Before you can use it in your projects you need to add the following compile line to your Gradle dependencies block in your build.gradle file.

-Placeholder And Error Fallback
In the above code snippet, I have just downloaded the image and displayed on ImageView. But that is not enough always. For any real time application, you must think of all possible cases. Now we need an placeholder and error fallback for our ImageView. Placeholder image will be shown before the image is loaded. Error fallback will be shown if, there is an error while downloading image. However both fallback and placeholder are optional.

-Image Resizing and Cropping
you are not sure about the size of the image loaded from the remote server that what will be the size of the image . so in this code snippet image is resized to 200X200 and center cropped.