1. Set Layout properties:
<imageview android:scaletype= "Fitxy"/>
2.BitmapUtils class--bitmap object with a specified circle
public static Bitmap Circlebitmap (Bitmap source) { //Gets the width of the Bitmap int width = source.getwidth (); The width value of the bitmap as the new bitmap's wide height value. Bitmap Bitmap = Bitmap.createbitmap (width, width, Bitmap.Config.ARGB_8888); Using this bitmap as a benchmark, create a canvases canvas canvas = new canvas (bitmap); Paint paint = new paint (); Paint.setantialias (true); Draw a circle canvas.drawcircle on the canvas (WIDTH/2, WIDTH/2, WIDTH/2, paint); To set how images are handled when the picture intersects //setxfermode: Sets the mode of processing when the image being drawn intersects, it contains the common patterns: //porterduff.mode.src_in Take two layers of image intersection part, Show only the upper image //porterduff.mode.dst_in take the two-layer image intersection section, showing only the underlying image Paint.setxfermode (New Porterduffxfermode ( PorterDuff.Mode.SRC_IN)); Draw Bitmap canvas.drawbitmap (source, 0, 0, paint) on the canvas; return bitmap;}
3.BitmapUtils class--Compress picture
Implementation of image compression processing//Setting wide height must use floating-point type, otherwise result in compression ratio: 0public static Bitmap Zoom (Bitmap source,float width, float height) { Matrix Matrix = new Matrix (); Image compression processing Matrix.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 ()
Get Picture Picasso.with (This.getactivity ()) using Picasso networking. Load (User.getimageurl ()). Transform (New transformation () { @Override public Bitmap transform (Bitmap source) {//Download Bitmap object in memory after// compression processing Bitmap Bitmap = Bitmaputils.zoom (source, uiutils.dp2px), uiutils.dp2px (()); Round treatment bitmap = Bitmaputils.circlebitmap (bitmap); Recycling Bitmap Resources source.recycle (); return bitmap; } @Override Public String key () { return "";//need to guarantee that the return value cannot be null. Otherwise the error }). into (Ivmeicon);
Picasso via URL-a circular display of the user's avatar