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 (100, 100)];5}
Show:
2. Cut the picture to make the picture circle: 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:
1-(void) DrawRect: (cgrect) Rect 2 {3/ /Draw a circle so that you can specify a range of pictures to be displayed later 4 //Get the Graphics context 5 cgcontextref ctx= Uigraphicsgetcurrentcontext (); 6 cgcontextaddellipseinrect (CTX, CGRectMake (s), 8, 7); The range of content that can be displayed in the specified context is the range of the Circle 9 Cgcontextclip (CTX), UIImage *image2=[uiimage imagenamed:@ "Me"];11 [image2 drawatpoint:cgpointmake (100, 100)];12}
Display: 3. Cut the picture to show the code in the picture triangle:
1-(void) DrawRect: (cgrect) Rect 2 {3 4 //Draw a triangle so that you can later specify a range for the picture to be displayed 5 //Get the graphics context 6 cgcontextref ctx= Uigraphicsgetcurrentcontext (); 7// Cgcontextaddellipseinrect (CTX, CGRectMake (8, 100, +)); Cgcontextmovetopoint (CTX, 100); 9 Cgcontextaddlinetopoint (CTX, max); Cgcontextaddlinetopoint (CTX, Cgcontextclosepath), one-to -one (CTX); Note: Specify the range (that is, the method that specifies the cut must be called before drawing the range) the range of content that can be displayed in the specified context is the range of the Circle Cgcontextclip (CTX); UIImage * Image2=[uiimage imagenamed:@ "Me"];18 [image2 drawatpoint:cgpointmake (100, 100)];19}
Show:
iOS Development UI Chapter-quartz2d use (Picture clipping)