Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use Android Picasso library to download images?

Why should I download the images via the Picasso library instead of just using this code:

private Bitmap DownloadImage(String URL)  {     Bitmap bitmap = null;      InputStream in = null;       try      {         in = OpenHttpGETConnection(URL);         bitmap = BitmapFactory.decodeStream(in); in.close();     }      catch (Exception e)      {         Log.d("DownloadImage", e.getLocalizedMessage());     }      return bitmap;  } 

Another question:

Does Picasso download the image in the UI or by background thread?

like image 774
user3376321 Avatar asked Mar 11 '14 16:03

user3376321


People also ask

What is use of Picasso library in Android?

Picasso is open source and one of the widely used image download libraries in Android. It is created and maintained by Square. It is among the powerful image download and caching library for Android. Picasso simplifies the process of loading images from external URLs and displays them on your application.

What is Android Picasso?

Picasso is an image library for Android. It's created and maintained by Square, and caters to image loading and processing. It simplifies the process of displaying images from external locations. In many cases only a few lines of code is required to implement this neat library.

Which library do we use to display images from Internet in Android?

Fresco is a powerful image loading library for displaying images in Android applications. Fresco supports Android 2.3 (Gingerbread) and later. This powerful library developed by the good folks at Facebook. It loads images from the internet, local storage, and display a placeholder until the image has appeared.

Which is better Picasso or glide Android?

Glide's loading times are faster and it uses a small amount of memory for cache, but the library size is quite large. It, too, is easy to implement. Glide might be a better alternative to Picasso when memory footprint is less of a concern or more and larger images need to be processed.


2 Answers

Just for the record for anyone new to Android or perhaps moving to Android from iOS ..........

Until something drastically changes, you absolutely have to use Picasso. Not a joke.

Honestly, it's that simple. The advantages are unbelievable.

It's this easy to use:

Picasso.   with(State.mainContext).   load(parseImageFile.getUrl()).   into(null); 

You very simply:

must do caching, and threading, with image handling on Android.

It's that simple. Unless you want to write that from scratch, you simply must use Picasso.

Note that ParseImageFile essentially doesn't work - it is utterly useless about caching and so on. There are admirable alternatives to Picasso (such as Universal Image Loader, check it out), but none work as well as Picasso, for now 2014.

Note if you move to super-advanced-stuffs... The only thing better than Picasso, is to make the move to Volley. but that is a huge leap.

Note that ListView scrolling on android is much, much more problematic than table handling scrolling on iOS. You could say, Android + Picasso is MORE LIKE the situation on iOS, where all the work is already done for scrolling large table views with images.

For today, Picasso is - simply - a central part of any Android app whatsoever. Thank goodness, it is one line of code - no setup, nothing.

Again, the only thing "better than" Picasso is if you move to Volley.

BTW here's an excellent long article on Volley v. Picasso, if you need that...

http://www.bignerdranch.com/blog/solving-the-android-image-loading-problem-volley-vs-picasso/

like image 76
Fattie Avatar answered Sep 22 '22 09:09

Fattie


Picasso download the image in another thread and it manages for you:

  • the placeholder in the meantime the image is still downloading
  • resizing
  • cropping/centering/scaling
  • caching ( you don't have to download the image every time)
  • it even does "image fade in", which is popular/normal now

It's extremely simple, here is an example:

    Picasso.with(context)            .load(url)            .placeholder(R.drawable.placeholder)            .resize(imgWidth, imgHeight)            .centerCrop()            .into(image); 
like image 31
Sarpe Avatar answered Sep 20 '22 09:09

Sarpe