Picasso is obtained through URL-the circular display of the user's profile picture, and picasso's profile picture

Source: Internet
Author: User

Picasso is obtained through URL-the circular display of the user's profile picture, and picasso's profile picture

1. Set layout attributes:

<ImageView    android:scaleType="fitXY"/>

2. BitmapUtils class -- get the Bitmap object of the specified circle

Public static Bitmap circleBitmap (Bitmap source) {// obtain the Bitmap width int width = source. getWidth (); // use the Bitmap width value as the width value of the new bitmap. Bitmap bitmap = Bitmap. createBitmap (width, width, Bitmap. config. ARGB_8888); // based on this bitmap, create a Canvas canvas Canvas = new Canvas (bitmap); Paint paint = new Paint (); paint. setAntiAlias (true); // draw a circle canvas on the canvas. drawCircle (width/2, width/2, width/2, paint); // sets the processing method when the image is intersecting. // setXfermode: set the processing method when the drawn image is intersecting. The common modes include: // PorterDuff. mode. SRC_IN uses the intersection of two layers to show only the upper layer image // PorterDuff. mode. DST_IN takes the intersection of two layers of images and only displays the lower layer image painting. setXfermode (new porterduxfermode (PorterDuff. mode. SRC_IN); // draw bitmap canvas on the canvas. drawBitmap (source, 0, 0, paint); return bitmap ;}

3. BitmapUtils class-compressing Images

// Implement image compression. // set the width and height to the floating point type. Otherwise, the compression ratio is 0 public static Bitmap zoom (Bitmap source, float width, float height) {Matrix matrix = new Matrix (); // The compression processing matrix of the image. postScale (width/source. getWidth (), height/source. getHeight (); Bitmap bitmap = Bitmap. createBitmap (source, 0, 0, source. getWidth (), source. getHeight (), matrix, false); return bitmap ;}

4. display the circular image according to user. getImageurl ()

// Use Picasso to obtain the Picasso image over the Internet. with (this. getActivity ()). load (user. getImageurl ()). transform (new Transformation () {@ Override public Bitmap transform (Bitmap source) {// bitmap object in the downloaded memory // Bitmap bitmap = BitmapUtils for compression processing. zoom (source, UIUtils. dp2px (62), UIUtils. dp2px (62); // bitmap = BitmapUtils for circular processing. circleBitmap (bitmap); // recycles the bitmap resource source. recycle (); return bitmap;} @ Override public String key () {return ""; // You must ensure that the returned value cannot be null. Otherwise, an error is returned.}). into (ivMeIcon );

  

  

  

Related Article

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.