#import "ViewController.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.}- (void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event{//get the picture you want to trimUIImage *image = [UIImage imagenamed:@"Papa"];//rect set for the pictureCGRect Imagerect = CGRectMake (0,0, Image.size.width, image.size.height);//turn on the graphics contextUigraphicsbeginimagecontextwithoptions (Image.size, NO,0.0);//Get the graphics contextCgcontextref Bitmapcontext =Uigraphicsgetcurrentcontext ();//draw the path of a circleCgcontextaddellipseinrect (Bitmapcontext, imagerect);//cut out the circle pathCgcontextclip (bitmapcontext);//Add a picture in context[Image Drawinrect:imagerect];//set a border for a picture//set width to borderCgcontextsetlinewidth (Bitmapcontext,5); //set color for borders[[Uicolor Bluecolor]Set]; Cgcontextaddellipseinrect (Bitmapcontext, imagerect);//Draw the BorderCgcontextstrokepath (Bitmapcontext); //get this pictureUIImage *newimage =Uigraphicsgetimagefromcurrentimagecontext ();//End Bitmap editingUigraphicsendimagecontext ();//Show PicturesUiimageview *imageview = [[Uiimageview alloc] Initwithframe:cgrectmake (0,0, $, $)]; [Self.view Addsubview:imageview]; Imageview.image=NewImage;//Save Picture//first dump the picture NSData, call the Write methodNSData *imagedata =uiimagepngrepresentation (newimage); [ImageData WriteToFile:@"/users/mac/desktop/new.png"Atomically:yes]; }
2016-1-9 Quartz frame learning, crop and set borders