1.1 Quartz 2D drawing, 1.1quartz2d drawing

Source: Internet
Author: User

1.1 Quartz 2D drawing, 1.1quartz2d drawing

Quartz2D drawing steps:  
1. Get the [graphic context] Object -- (get draft paper)
2. Add [path] 2.1 splicing path (painting content) 2.2 to the context (put the content on the draft paper) to the [graphic context] object)
3. rendering -- (draw the image in the [graphic context] to the corresponding device) (display something based on the content on the draft paper)
Key Methods:
1 // obtain the context 2 CGContextRef ctx = UIGraphicsGetCurrentContext (); 3 4 // create a variable path (c) 5 CGMutablePathRef path = CGPathCreateMutable (); 6 7 // place the path in the context. 8 CGContextAddPath (ctx, path); 9 10 // create the path object (oc) 11 UIBezierPath * path = [UIBezierPath bezierPath]; 12 13 // render 14 CGContextStrokePath (ctx );

 

Quartz2D drawing method:  
Method 1: directly call the Quartz2D API for plotting
  • Slightly larger code
  • Comprehensive Functions
Step: 1. Obtain the drawing context 2. Draw the drawing to the drawing context 3. render the drawing on the drawing context to the corresponding device
Method 2: Call the API encapsulated by the UIKit framework for plotting (drawing by creating a path object)
  • Relatively simple code
  • Only some Quartz2D APIs are encapsulated.
  • Only Quartz2D native APIs can be called for unencapsulated functions.
  • Related Classes: CGPathRef and CGMutablePathRef
Step: 1. First cache the image to "path object, 2. Add the path object to the context object. 3. render the context object to the corresponding device, for example, draw an image or text to the control. (UIKit has been encapsulated)
Sample Code: Method 1:
1 # import "TDView. h "2 3 @ implementation TDView 4-(void) drawRect :( CGRect) rect {5 6 // 1. obtain the graph context of the current layer 7 CGContextRef ctx = UIGraphicsGetCurrentContext (); 8 9 // 2. concatenate the path and add the path to the context (the following code is a line segment) 10 CGContextMoveToPoint (ctx, 50, 50); 11 CGContextAddLineToPoint (ctx, 100,100 ); 12 13 // 3. rendering (drawing path) <move the path in the context to UIView> 14 CGContextStrokePath (ctx); // StrokeXxxx indicates draw line (edge) (hollow image) 15 CGContextFillPath (ctx ); // FillXxx indicates the filled image (solid image) 16} 17 @ end

Method 2:

1-(void) test2 2 {3 // 1. obtain the graphic context (layer) 4 CGContextRef ctx = UIGraphicsGetCurrentContext (); 5 6 // 2. splicing path 7 CGMutablePathRef path = CGPathCreateMutable (); 8 CGPathMoveToPoint (path, NULL, 50, 50); 9 CGPathAddLineToPoint (path, NULL, 100,100); 10 11 // 3. add the path to the context 12 CGContextAddPath (ctx, path); 13 14 // 4. rendering 15 CGContextStrokePath (ctx); 16}

 

 
If you have any questions, please send an e-mail to shorfng@126.com to contact me. By: Loto)

Related Article

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.