Picasso: A powerful image download and cache library built for Android

Source: Internet
Author: User

Brief introduction

In Android apps, images consume a lot of resources, but they provide a good visual experience for applications. Fortunately, Picasso provides a very easy way for your app to load images-usually one line of code can be done!

Picasso.with (context). Load ("Http://i.imgur.com/DvpvklR.png"). into (ImageView);

Picasso handles many of the pits loaded by Android tablets:

1) in adapter, the recycling and cancellation of ImageView are processed.

2) consumes minimal memory to deal with complex graphics transformations.

3) automatically cache pictures in memory and on disk.


Features download in adapter

Automatic detection of reuse in adapter, and once reuse is found, the previous download is automatically canceled.

@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);

Picture conversion

Transform the picture to better fit the layout, while also reducing the use of memory.

Picasso.with (context).  load (URL).  resize (  ). Centercrop (). into  (ImageView)

You can also customize the way images are converted to achieve more complex transformation requirements.

public class Cropsquaretransformation implements transformation {  @Override public Bitmap transform (bitmapsource) {    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;  }   @Override public String key () {return ' square () ';}}

Pass an instance of the Cropsquaretransformation class to the transform () function.

Placeholder Pictures

Picasso supports both "downloading" and "Picture Download Error" When the default picture is displayed.

Picasso.with (context).    load (URL).    placeholder (r.drawable.user_placeholder)    . Error (R.drawable.user_ Placeholder_error). into (ImageView);

Picasso will try to download at most three times, if the three download failed, it will show in the original location "Picture Download Error" When the picture.

Resource loading

Picasso supports resources, assets, files, and ContentProvider as the loading source for pictures.

Picasso.with (context). Load (R.drawable.landing_screen). into (ImageView1); Picasso.with (context). Load ("File:///android_asset/DvpvklR.png"). into (IMAGEVIEW2); Picasso.with (context). Load (NewFile (...)). Into (IMAGEVIEW3);

Debug indicator

Developers can display a small, colored triangle in the upper left corner of the image, with different colors indicating different sources of the picture's resources. It is possible to call the Setindicatorsenabled (True) method of the Picasso object.


Download

Http://repo1.maven.org/maven2/com/squareup/picasso/picasso/2.5.2/picasso-2.5.2.jar

Picasso's source code, examples, and this URL (http://square.github.io/picasso/) are on GitHub .

maven<dependency>  <groupId>com.squareup.picasso</groupId>  <artifactid>picasso </artifactId>  <version>2.5.2</version></dependency>gradlecompile ' com.squareup.picasso:picasso:2.5.2 '

Make a contribution to Picasso

If you want to contribute your code for Picasso development, you can go to GitHub, fork the code base, and then send us your changes (pull request).

When submitting your code, keep your code's habits and style consistent with the original so that you can keep your code as readable as possible. Also, to make sure your code compiles correctly, run MVN clean verify.

You need to agree with individual Contributorlicense agreement (CLA) to merge your code into the Picasso project.

Important Information

1]javadoc:http://square.github.io/picasso/javadoc/index.html

[2] Stackoverflow:http://stackoverflow.com/questions/tagged/picasso?sort=active

License

Copyright: Square, Inc.

Licensed under the Apache License, Version2.0 (the "License");

Except incompliance with the License.

Obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreedto in writing, software

Distributed under the License isdistributed on a "as is" BASIS,

Without warranties or CONDITIONS of anykind, either express or implied.

See the License for the specific languagegoverning permissions and

Limitations under the License.

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







Picasso: A powerful image download and cache library built for Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.