Quartz 2D Introduction

Source: Internet
Author: User

1. Quartz 2D is a two-dimensional drawing library that closely integrates with the iphone OS to work with all relevant frameworks, including Core Animation, OpenGL es, and Uikit.

2. Quartz's drawing function depends on 3 core concepts: Context, path, and state.

① Context: The user describes where the graphic is written, and the procedure is defined by Cgcontextref . In general, you can write to UIView or bitmaps.

② Path: The path is something that is often drawn in quartz. Initially, they are a collection of segments and arcs that are then drawn to the screen by strokes or fills.

③ states: States are used to save transform values, clipping paths, fill and stroke settings, alpha values, other blending modes, text features, and so on. You can use Cgcontextsavegstate to store the current state, which is where the Cgcontextrestoregstete restores the current state so that you can easily switch between complex drawing setups.

3. Commonly used classes

Use of Cgcontextaddarc

This function let me draw on the paper for a half a day to understand, I understand to share the next.

void Cgcontextaddarc (Cgcontextref C, CGFloat x, cgfloat y, cgfloat radius, cgfloat startangle, cgfloat endangle, int clock Wise

Cgcontextref does not explain that X, y is the dot coordinate, the startangle is the starting Radian, the Endangle is the end of the radian, clockwise 0 is clockwise, and 1 is counterclockwise.

Cgcontextaddarc (context, 0, 45* (m_pi/180), 0);

So the explanation for the above code is this:

1) StartAngle is the place of the 0, Green Arrow.

2) Endangle is the place of the 45, Yellow arrow.

3) Clockwise is 0, follow the Red Arrows to draw down the graph.

4) So the effect is a red fan.

Add: If clockwise is 1, it is a blue part of the area.

4. Example Drawing Circle

-(void) viewdidload {

[Super viewdidload];

/*

Baseview *view = [[Baseview alloc] Initwithframe:cgrectmake (10, 20, 300, 300)];

[Self.view Addsubview:view];

*/

uigraphicsbeginimagecontext(cgsizemake( )); // Create a graphics context

cgcontextref context = uigraphicsgetcurrentcontext(); // Returns the current context, usually referring to the context in the current UIKit object, but may also be a manually created context

Cgcontextsetrgbfillcolor(context, 1, 0, 0, 1.0);

Cgcontextbeginpath(context); // Create a new path

Cgcontextaddarc(context, ten, ten, ten, 0,2*m_pi, 1 );

Cgcontextfillpath(context); // End path

UIImage *redball = uigraphicsgetimagefromcurrentimagecontext();

Uigraphicsendimagecontext();

uiimageview *redballview = [[uiimageview alloc] initwithimage: RedBall];

Redballview.frame = CGRectMake (20, 20, 400, 400);

Redballview. Center = cgpointmake(onthe other);

[self. View addsubview: Redballview];

}

Quartz 2D Introduction

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.