Goal: crop a circular picture
Steps:
1. Load the picture you want to intercept
2. Set the Circle clipping area
2.1 Creating a circular path
2.2 Set the path to the cropping area
3. Drawing pictures
4. Get the picture from the context
5. Close the context
Code:
-(void) viewdidload { [super viewdidload]; Self.view.backgroundColor = [Uicolor colorwithwhite:0.819 alpha:1.000]; 0. Load the picture to be intercepted UIImage *image = [UIImage imagenamed:@ "High Circle"]; 1. Gets (opens) The graphics context (the graphics context is a square) uigraphicsbeginimagecontextwithoptions (Cgsizemake (Image.size.width, Image.size.width), NO, 0); 2. Set the circle clipping area, tangent to the picture//2.1 create the path of the circle uibezierpath *path = [Uibezierpath bezierpathwithroundedrect:cgrectmake (0, 0, Image.size.width, image.size.width) CORNERRADIUS:IMAGE.SIZE.WIDTH/2]; 2.2 Set the path to the clipping area [path Addclip]; 3. Draw the picture [Image Drawatpoint:cgpointzero]; 4. Get the picture from the context UIImage *clipedimage = Uigraphicsgetimagefromcurrentimagecontext (); 5. Close the context uigraphicsendimagecontext (); Self.imageView.image = Clipedimage; }
Original:
After cropping as:
Xcode cropping a picture