Quartz2D summary, iosquartz2d

Source: Internet
Author: User

Quartz2D summary, iosquartz2d

I have lost my mind. At least I have forgotten the context. I would like to summarize it and remember this interview.

 

The Quartz2D API comes from Core Graphics (that is why CGContextRef starts with CG) and needs to import CoreGraphics (?)

Graphical context: A CGContextRef type data

Role of the graphic context:

1. Save drawing information and drawing status

2. Determine the output target (where to draw) (the output target can be a PDF file, Bitmap, or display window ).

Bitmap Graphics ContextPDF Graphics ContextWindow Graphics ContextLayer Graphics ContextPrinter Graphics Context

Draw a view by yourself
Steps:
1. Create a new class inherited from UIView
2. Implement-(void) drawRect :( CGRect) rect method, and obtain the graph context of the current view in this method
3. Create your own drawing path and draw the Image Based on the path
4. Use the graphic context to render all the drawn content to the view

Of course, for example, the Bitmap graphic context does not have to be in-(void) drawRect :( CGRect) rect, you can directly create one:
// Create a bitmap context transform (CGSizeMake (200,200), NO, 0); // obtain the bitmap context CGContextRef ctr = UIGraphicsGetCurrentContext (); // draw the circle CGContextAddEllipseInRect (ctr, CGRectMake (50, 50,100,100); // render CGContextStrokePath (ctr); // obtain the image UIImage * img = UIGraphicsGetImageFromCurrentImageContext () from the context (); UIImageView * imageView = [[UIImageView alloc] initWithImage: img]; CGRect frame = imageView. frame; frame. origin = CGPointMake (50, 50); imageView. frame = frame; [self. view addSubview: imageView];

To be continued...

Part reference from: http://www.jianshu.com/p/eecffec3b7af



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.