iOS Development UI Chapter-quartz2d use (Picture clipping)

Source: Internet
Author: User

iOS Development UI Chapter-quartz2d use (Picture clipping)

First, the use of quartz2d to complete the picture cut 1. Display the picture in a custom view before drawing it to the view. According to the original size, the picture is drawn to a point. Code:
1 -(void) DrawRect: (cgrect) rect2{3     UIImage *image2=[ UIImage imagenamed:@ "me"]; 4     [Image2 drawatpoint:cgpointmake (+)]; 5 }

Show:

2. Cut the picture to make the picture appear roundIdeas:Draw a circle first, let the picture appear inside the circle, the outside part is not displayed.Note:The displayed range is limited to the specified clipping range, and no matter what is drawn in the context, it will not be displayed if it is outside the range. Code:
1- (void) DrawRect: (cgrect) Rect2 {3     //draw a circle so that you can specify a range of pictures to be displayed later4     //Get the graphics context5Cgcontextref ctx=Uigraphicsgetcurrentcontext ();6Cgcontextaddellipseinrect (CTX, CGRectMake ( -, -, -, -));7     8     //specifies that the range of content that can be displayed in the context is the range of circles9 Cgcontextclip (CTX);TenUIImage *image2=[uiimage imagenamed:@"Me"]; One[Image2 Drawatpoint:cgpointmake ( -, -)]; A}
Display: 3. Cut the picture to show the code in the picture triangle:
1- (void) DrawRect: (cgrect) Rect2 {3 4     //Draw a triangle so you can specify a range to display the picture later5     //Get the graphics context6Cgcontextref ctx=Uigraphicsgetcurrentcontext ();7 //Cgcontextaddellipseinrect (CTX, CGRectMake ( +, +, +));8Cgcontextmovetopoint (CTX, -, -);9Cgcontextaddlinetopoint (CTX, -, Max);TenCgcontextaddlinetopoint (CTX, $, Max); One Cgcontextclosepath (CTX); A      -      -     //Note: Specify the range (that is, the method that specifies the cut must be called before drawing the range) the     //specifies that the range of content that can be displayed in the context is the range of circles - Cgcontextclip (CTX); -UIImage *image2=[uiimage imagenamed:@"Me"]; -[Image2 Drawatpoint:cgpointmake ( -, -)]; +}

Show:

    

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.