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