In Android, Google only provides a circular operation of the picture, but does not implement a circular operation on the picture, so we do not do this, we will use the framework for the design (the following framework for the as written):
Https://github.com/monsterLin/RoundedImageView
Https://github.com/pungrue26/SelectableRoundedImageView
Https://github.com/hdodenhof/CircleImageView
Https://github.com/MostafaGazar/CustomShapeImageView
Https://github.com/siyamed/android-shape-imageview
Here we do this by using Roundedimageview:
First we import the open source framework into the project:
After the import is successful-
The first way: Write the XML file directly:
<Com.makeramen.roundedimageview.RoundedImageViewXmlns:app= "Http://schemas.android.com/apk/res-auto"Android:id= "@+id/imageview1"Android:layout_width= "40DP"Android:layout_height= "40DP"android:src= "@drawable/photo"App:riv_corner_radius= "30dip"App:riv_border_width= "2dip"App:riv_border_color= "#333333"App:riv_mutate_background= "true"App:riv_oval= "true" />
The second way: implemented by code:
Public Static classRoundeddrawableextendsdrawable {protected Final floatCornerradius; protected Final intmargin; protected FinalRECTF Mrect =NewRECTF (), Mbitmaprect; protected FinalBitmapshader Bitmapshader; protected FinalPaint paint; PublicRoundeddrawable (Bitmap Bitmap,intCornerradius,intmargin) { This. Cornerradius =Cornerradius; This. Margin =margin; Bitmapshader=NewBitmapshader (Bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); Mbitmaprect=NewRECTF (margin, margin, bitmap.getwidth ()-Margin, bitmap.getheight ()-margin); Paint=NewPaint (); Paint.setantialias (true); Paint.setshader (Bitmapshader); } @Overrideprotected voidOnboundschange (Rect bounds) {Super. Onboundschange (bounds); Mrect.set (margin, margin, bounds.width ()-Margin, bounds.height ()-margin); //Resize the original bitmap to fit the new boundMatrix Shadermatrix =NewMatrix (); Shadermatrix.setrecttorect (Mbitmaprect, Mrect, Matrix.ScaleToFit.FILL); Bitmapshader.setlocalmatrix (Shadermatrix); } @Override Public voidDraw (canvas canvas) {canvas.drawroundrect (Mrect, Cornerradius, Cornerradius, paint); } @Override Public intgetopacity () {returnpixelformat.translucent; } @Override Public voidSetalpha (intAlpha) {Paint.setalpha (alpha); } @Override Public voidSetcolorfilter (Colorfilter CF) {paint.setcolorfilter (CF); }}imageaware.setimagedrawable (NewRoundeddrawable (bitmap, Cornerradius, margin));
Appendix:
Open source framework for Eclipse: Http://files.cnblogs.com/files/boy1025/roundedimageview.zip
Android Programming-the implementation of circular images