Cut a normal picture into a circle and circle the picture with a circular border
The code extraction is the UIImage classification method, as follows:
1+ (Instancetype) Circleimagewithname: (NSString *) name BorderWidth: (cgfloat) borderWidth bordercolor: (Uicolor *) bordercolor2 {3 //1. Loading the original4UIImage *oldimage =[UIImage imagenamed:name];5 6 //2. Open Context7CGFloat Imagew = OldImage.size.width +2*BorderWidth;8CGFloat Imageh = OldImage.size.height +2*BorderWidth;9Cgsize imageSize =Cgsizemake (Imagew, Imageh);TenUigraphicsbeginimagecontextwithoptions (ImageSize, NO,0.0); One A //3. Get the current context -Cgcontextref CTX =Uigraphicsgetcurrentcontext (); - the //4. Draw the border (great circle) -[BorderColorSet]; -CGFloat Bigradius = Imagew *0.5;//Circle Radius -CGFloat CenterX = Bigradius;//Center +CGFloat centery =Bigradius; -Cgcontextaddarc (CTX, CenterX, CenterY, Bigradius,0, M_PI *2,0); +Cgcontextfillpath (CTX);//Draw a circle A at //5. Small Circle -CGFloat Smallradius = Bigradius-BorderWidth; -Cgcontextaddarc (CTX, CenterX, CenterY, Smallradius,0, M_PI *2,0); - //cropping (the things that are drawn later will be affected by clipping) - Cgcontextclip (CTX); - in //6. Drawing - [Oldimage drawinrect:cgrectmake (BorderWidth, BorderWidth, OldImage.size.width, OldImage.size.height)]; to + //7. Take a picture -UIImage *newimage =Uigraphicsgetimagefromcurrentimagecontext (); the * //8. End Context $ Uigraphicsendimagecontext ();Panax Notoginseng - returnNewImage; the}
:
Picture trimmed round Head