Picasso - Image downloading and caching library for Android

useful android libraries
Site Admin
Posts: 35
Joined: Tue Nov 18, 2014 2:39 pm

Picasso - Image downloading and caching library for Android

Postby vivekkalady » Sat Nov 22, 2014 9:19 am

Picasso allows for hassle-free image loading in your application—often in one line of code!


  • Create new Android project using your favorite IDE (I’ll using Eclipse).
  • Download Android Picasso library.
  • Put the downloaded jar file into your project’s “libs” folder.

Simple Usage

Code: Select all


context is the application context.if you are in an fragment, you can use getActivity()
imageView is the object of imageview when image is to be placed

Place Holders

Picasso supports both download and error placeholders as optional features.

Code: Select all


Resource Loading

Resources, assets, files, content providers are all supported as image sources.

Code: Select all

Picasso.with(context).load(new File(...)).into(imageView2);

Original Source : http://square.github.io/picasso/

Save Loaded image to SDCard using Target Class

Target class provided with the Picasso library to convert our image to bitmap. It actually has 3 three methods but we are just concerned with onBitmapLoaded as we only need to save the image to disk when it is loaded.

Code: Select all


Code: Select all

private Target target = new Target() {
   public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
      new Thread(new Runnable() {
         public void run() {

            File file = new File(Environment.getExternalStorageDirectory().getPath() + "/image1.jpg");
            try {
               FileOutputStream ostream = new FileOutputStream(file);
               bitmap.compress(CompressFormat.JPEG, 80, ostream);
            } catch (Exception e) {

   public void onBitmapFailed(Drawable errorDrawable) {}

   public void onPrepareLoad(Drawable placeHolderDrawable) {
      if (placeHolderDrawable != null) {}

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 1 guest