First, the use of quartz2d to complete the picture cut
1. Display the image in a custom view
First, draw the picture onto 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 }
View Code
Show:
2. Cut the picture to make the picture appear round
Idea: Draw a circle first, let the picture appear inside the circle, the outside part does not show.
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 the range is exceeded. Code:
- (void) DrawRect: (cgrect) rect{//draw a circle so that you can specify a range of pictures to be displayed later//Get the graphics contextCgcontextref ctx=Uigraphicsgetcurrentcontext (); Cgcontextaddellipseinrect (CTX, CGRectMake ( -, -, -, -)); //specifies that the range of content that can be displayed in the context is the range of circlesCgcontextclip (CTX); UIImage*image2=[uiimage imagenamed:@"Me"]; [Image2 Drawatpoint:cgpointmake ( -, -)];}
View CodeShow:
Text top-top iOS Development UI Chapter-quartz2d use (Picture clipping)
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) rect{3 UIImage *image2=[uiimage imagenamed:@ "me"]; 4 [Image2 drawatpoint:cgpointmake (+)]; 5}
Show:
2. Cut the picture to make the picture appear roundidea: Draw a circle first, let the picture appear inside the circle, the outside part does not show. 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 the range is exceeded. Code: Press CTRL + C to copy code<textarea style="width: 768.667px; height: 222.133px; font-family: Courier New; font-size: 12px; line-height: 1.5;"></textarea>Press CTRL + C to copy the code display: 3. Cut the picture to show the picture triangle
Code:
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 ( -, -)]; +}
View Code
Show:
"IOS" quartz2d picture clipping