1.Picasso Brief Introduction
Picasso is a powerful image download and cache Gallery for the square company. The official website is:http://square.github.io/picasso/
Simply need a code to download and set the image on the ImageView.
Picasso.with (context). Load ("Http://i.imgur.com/DvpvklR.png"). into (ImageView);
2. Main Features
2.1Adapter Downloads
When using Listview,gridview, you actively detect adapter reuse (re-use), cancel the download, and use the cache.
@Override public void GetView (int position, view Convertview, ViewGroup parent) { Squaredimageview View = (squaredimag Eview) Convertview; if (view = = null) { view = new Squaredimageview (context); } String url = getItem (position); Picasso.with (context). Load (URL). into (view);
2.2 Image processing and transformation
Transform the image to better fit layout controls, and reduce memory overhead.
Picasso.with (context). load (URL). resize ($). Centercrop (). into (ImageView)
Of course, we can also write our own transformation class, but we must implement the transformation interface, such as:
/** * Define the interface itself, realize the image is reduced to half the original */public class Cropsquaretransformation implements transformation {@Overridepublic Bitmap Transform (Bitmap source) {int size = Math.min (Source.getwidth (), Source.getheight ()); int x = (Source.getwidth ()-size)/ 2;int y = (source.getheight ()-size)/2; Bitmap result = Bitmap.createbitmap (source, x, y, size, size); if (Result! = Source) {source.recycle ();} return result;} @Overridepublic String Key () {return ' square () ';}}
Then you can set the Transform method:
Picasso.with (this). Load ("Http://i.imgur.com/DvpvklR.png"). Transform (New Cropsquaretransformation ()). into (iv_ TEST2);
For example, the following:
2.3. Supports setting up images before loading, and loading failed images.
Such as:
Picasso.with (this). load ("Http://i.imgur.com/DvpvklR.png") . Placeholder (R.DRAWABLE.ABC) . Error ( R.drawable.ic_launcher) . Transform (New Cropsquaretransformation ()) . into (IV_TEST1);
ImageView display Abc.png when created, assuming the load succeeds, the dvpvklr.png is displayed, assuming the load fails, the ic_launcher.png is displayed.
2.4 Support for loading local images and image files in SDcard.
Picasso.with (context). Load (R.drawable.landing_screen). into (ImageView1); Picasso.with (context). Load (new File (...)). Into (IMAGEVIEW2);
picasso:http://square.github.io/picasso/
not for commercial purposes without consent