PackageLiu.roundimagedemo.view;ImportAndroid.graphics.Bitmap;ImportAndroid.graphics.BitmapShader;ImportAndroid.graphics.Canvas;ImportAndroid.graphics.Paint;Importcom.squareup.picasso.Transformation;/*** Created by Liu Nan on 2016/8/31 0031.23:09*/ Public classCircletransformImplementsTransformation {@Override PublicBitmap Transform (Bitmap source) {/*** Find out which small and high*/ intSize =math.min (Source.getwidth (), Source.getheight ()); /*** Seek center point*/ intx = (Source.getwidth ()-size)/2; inty = (source.getheight ()-size)/2; /*** Generate Bitmap*/Bitmap Squaredbitmap=Bitmap.createbitmap (source, x, y, size, size); if(Squaredbitmap! =source) { //Releasesource.recycle (); } /*** Create new Bitmap*/Bitmap Bitmap=bitmap.createbitmap (size, size, source.getconfig ()); /*** Canvas Brush*/Canvas Canvas=NewCanvas (bitmap); Paint Paint=NewPaint (); Bitmapshader Shader=NewBitmapshader (Squaredbitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); Paint.setshader (shader); Paint.setantialias (true); floatR = Size/2f; /*** Draw a circle*/Canvas.drawcircle (R, R, R, paint); Squaredbitmap.recycle (); returnbitmap; } @Override PublicString Key () {return"Circle"; }}
Picasso.with (this). Load ("Http://img1.3lian.com/2015/w7/68/d/85.jpg"). Transform (new Circletransform ()) . into (Mnetimageview);
Picasso setting rounded corners