2016-1-9 Quartz frame learning, crop and set borders

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.