Xcode cropping a picture

Source: Internet
Author: User

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

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.