Paths (reprint)

Source: Internet
Author: User

several important elements in the paths

Points

void Cgcontextmovetopoint (

Cgcontextref C,

CGFloat x,

CGFloat y

);

Specify a point to be current

The quartz will follow the current point and after a correlation function is executed, the current point will change accordingly.

Lines

Some of the related functions

void Cgcontextaddlinetopoint (

Cgcontextref C,

CGFloat x,

CGFloat y

);

Create a line from current point to (x, y)

Then the current point becomes (x, y)

void Cgcontextaddlines (

Cgcontextref C,

Const Cgpoint points[],

size_t Count

);

Create multiple lines, such as points with two points, then draw two straight lines from current point to (X1,y1),

Then is (x1,y1) to (X2,y2)

Then the current point becomes the last dot in the points.

Arcs

The first of two methods to create radians

void Cgcontextaddarc (

Cgcontextref C,

x coordinate of CGFloat x,//Center

x coordinate of CGFloat y,//Center

Radius of CGFloat radius,//Circle

CGFloat startangle,//Start Radian

CGFloat Endangle,//End Radian

int clockwise//0 means clockwise, 1 is counterclockwise

);

If you want to create a complete circle, then the beginning Radian is the 0 end radian is 2pi, because the circumference of the circle is 2*pi*r.

Finally, when the function finishes executing, the current point is reset to (x, y).

It is also important to note that if the current path already has a subpath, then another effect of this function is

There will be a straight line, from current point to the beginning of the arc

The second Kind

void Cgcontextaddarctopoint (

Cgcontextref C,

CGFloat x1,//x-coordinate of endpoint 1

CGFloat y1,//y-coordinate of endpoint 1

CGFloat x2,//x-coordinate of Endpoint 2

CGFloat y2,//y-coordinate of Endpoint 2

CGFloat Radius//Radius

);

Principle: First draw two lines, these two lines are current point to (X1,y1) and (X1,y1) to (X2,y2).

This is the emergence of a two-ray with a vertex (x1,y1),

It then defines the radius length, which is perpendicular to the two rays, which determines a circle and a better understanding, but the individual thinks the position of the tangent point 1 is wrong.

Finally, when the function finishes executing, the current point is reset to (X2,Y2).

It is also important to note that if the current path already has a subpath, then another effect of this function is

There will be a straight line, from current point to (X1,Y1)

Curves

Draw a curve, usually a straight line, and then define several control points to bend the line.

Three-time curve function

void Cgcontextaddcurvetopoint (

Cgcontextref C,

CGFloat cp1x,//Control point 1 x coordinate

CGFloat cp1y,//Control point 1 y-coordinate

CGFloat CP2X,//Control point 2 x coordinate

CGFloat cp2y,//Control point 2 y-coordinate

CGFloat x,//end of line x coordinate

CGFloat y//end of line y coordinate

);

A closed curve is formed if the second control point (CP2X,CP2Y) is closer to current points than (cp1x,cp1y).

Two-time curve function

void Cgcontextaddquadcurvetopoint (

Cgcontextref C,

CGFloat CPX,//control point x coordinate

CGFloat cpy,//Control point y-coordinate

CGFloat x,//end of line x coordinate

CGFloat y//end of line y coordinate

);

After executing the function, it seems that the current point does not change, no specific test

ellipses

void Cgcontextaddellipseinrect (

Cgcontextref context,

CGRect rect//One rectangle

);

If the rectangle is a square, then the drawing is a circle

After executing the function, it seems that the current point does not change, no specific test

rectangles

void Cgcontextaddrect (

Cgcontextref C,

CGRect rect

);

Draw multiple rectangles at once

void Cgcontextaddrects (

Cgcontextref C,

Const CGRect rects[],

size_t Count

);

It is important to note that the draw rectangle has something special, and the current point does not change

Creating a Path

Call function Cgcontextbeginpath Start create path, line call function Cgcontextmovetopoint Set start point

Then start drawing the path you want to draw and notice the points:

1.Lines, arcs, and curves, starting from current point

2. If you want to close a path, call the function Cgcontextclosepath to connect the current point and the starting point.

3. When painting arcs, quartz will draw a line from current point to starting

4. There is no third line when you draw a rectangle.

5. After you have created the path, you must call the painting function fill or stroke the path, or you will not draw the above stuff on the corresponding device "

6. When you start creating a new path, use the function Cgcontextbeginpath.

Related functions and data types for reusing paths

Cgpathcreatemutable similar to Cgcontextbeginpath

Cgpathmovetopoint similar to Cgcontextmovetopoint

Cgpathaddlinetopoint similar to Cgcontextaddlinetopoint

Cgpathaddcurvetopoint similar to Cgcontextaddcurvetopoint

Cgpathaddellipseinrect similar to Cgcontextaddellipseinrect

Cgpathaddarc similar to Cgcontextaddarc

Cgpathaddrect similar to Cgcontextaddrect

Cgpathclosesubpath similar to Cgcontextclosepath

Cgpathref

Cgmutablepathref

Add a path to the graphics context using the Cgcontextaddpath function

void Cgcontextaddpath (

Cgcontextref context,

Cgpathref Path

);

Painting a Path

Stroking: Draw a path

Filling: Enclosing area of the fill path

Parameters that affect stroking

Line width

void Cgcontextsetlinewidth (

Cgcontextref C,

CGFloat width

);

Line join: The style of a curve, as in a sleek way

void Cgcontextsetlinejoin (

Cgcontextref C,

Cglinejoin Join

);

Line cap: The style of the ends of the lines, such as the smooth ends

void Cgcontextsetlinecap (

Cgcontextref C,

Cglinecap Cap

);

Miter limit: This parameter has an effect when line join IS in the Miter join mode

void Cgcontextsetmiterlimit (

Cgcontextref C,

CGFloat limit

);

Line dash pattern: dashed lines related

void Cgcontextsetlinedash (

Cgcontextref C,

CGFloat phase,

Const CGFloat lengths[],

size_t Count

);

Stroke Color Space

void Cgcontextsetstrokecolorspace (

Cgcontextref C,

Cgcolorspaceref ColorSpace

);

Stroke Color

void Cgcontextsetstrokecolor (

Cgcontextref C,

Const CGFloat components[]

);

void Cgcontextsetstrokecolorwithcolor (

Cgcontextref C,

Cgcolorref Color

);

Stroke pattern (and transparency related)

void Cgcontextsetstrokepattern (

Cgcontextref C,

Cgpatternref pattern,

Const CGFloat components[]

);

Related functions of stroking

Strokes the current path.

void Cgcontextstrokepath (

Cgcontextref C

);

Strokes the specified rectangle.

void Cgcontextstrokerect (

Cgcontextref C,

CGRect rect

);

Strokes the specified rectangle, using the specified width.

void Cgcontextstrokerectwithwidth (

Cgcontextref C,

CGRect Rect,

CGFloat width

);

Strokes the specified ellipse.

void Cgcontextstrokeellipseinrect (

Cgcontextref context,

CGRect rect

);

Strokes some straight lines.

void Cgcontextstrokelinesegments (

Cgcontextref C,

Const Cgpoint points[],

size_t Count

);

The decision is stroking or filling.

void Cgcontextdrawpath (

Cgcontextref C,

Cgpathdrawingmode mode

);

Filling a Path

When a path is populated, the paths inside the path are filled independently.

If the path is overlapping, determine whether a point is filled, there are two rules

1,nonzero Winding Number rule: non-0 rules, if a point is crossed from left to right, counter +1, from right to left, counter-1, and finally, if the result is 0, then no padding, if nonzero, then padding.

2,even-odd rule: Parity rules, if a point is crossed, then +1, and finally an odd number, then to be filled, even the number is not filled, and the direction is not related.

Function

Description

Cgcontexteofillpath

Populating the current path with parity rules

Cgcontextfillpath

Populating the current path with a non-0-wrap rule

Cgcontextfillrect

Fills the specified rectangle

Cgcontextfillrects

Fills a specified number of rectangles

Cgcontextfillellipseinrect

Fills the ellipse in the specified rectangle

Cgcontextdrawpath

Two parameters determine the fill rule, Kcgpathfill represents the rule with a non-0 number of rules, kcgpatheofill represents a parity rule, kcgpathfillstroke represents a fill, kcgpatheofillstroke represents a stroke, not a fill

Setting Blend Modes

Set when a color is covered on another color, two colors how to mix

The default method is

result = (Alpha * foreground) + (1-alpha) * background

Cgcontextsetblendmode: Set blend mode.

Cgcontextsavegstate: Save blend mode.

Cgcontextrestoregstate: Use this function to restore the blend mode before saving.

The following two pictures, the first one is the background map, the second is the foreground map, are opaque images

Note: This rule can also be applied to a picture, using the function: Cgcontextsetblendmode to set

Normal Blend Mode

This mode is the default mode, and the foreground map covers the background map.

Multiply Blend Mode

When calling the function Cgcontextsetblendmode, use the parameter kcgblendmodemultiply.

Mixing two colors, the final color will be darker than the original two colors.

Screen Blend Mode

Usage Parameters: Kcgblendmodescreen

Turn the foreground and background map color first, then mix, and the result is that the blend is brighter than the previous color, and the foreground is not mixed into white.

Overlay Blend Mode

Using the parameter Kcgblendmodeoverlay

Bright depending on background map

Darken Blend Mode

Kcgblendmodedarken

Lighten Blend Mode

Kcgblendmodelighten

Color Dodge Blend Mode

Kcgblendmodecolordodge

Color Burn Blend Mode

Kcgblendmodecolorburn

Soft Light Blend Mode

Kcgblendmodesoftlight

Hard Light Blend Mode

Kcgblendmodehardlight

Difference Blend Mode

Kcgblendmodedifference

Exclusion Blend Mode

Kcgblendmodeexclusion

Hue Blend Mode

Kcgblendmodehue

Saturation Blend Mode

Kcgblendmodesaturation

Color Blend Mode

Kcgblendmodecolor

Luminosity Blend Mode

Kcgblendmodeluminosity

Clipping to a Path

This is used if we just want to print the part of the picture to the screen.

Cgcontextbeginpath (context);

Cgcontextaddarc (context, W/2, H/2, (w>h) h:w)/2, 0, 2*PI, 0);

Cgcontextclosepath (context);

Cgcontextclip (context);

Function

Description

Cgcontextclip

To clip the current graphics context using a non-0 wrap rule

Cgcontexteoclip

Clip the current context using a parity rule

Cgcontextcliptorect

Sets the intersection of a rectangular area and the current clipping region

Cgcontextcliptorects

Sets the intersection of some rectangular regions and the current clipping region

Cgcontextcliptomask

Maps a mask into the specified rectangle and intersects it with the current clipping area of the graphics context. Any subsequent path drawing your perform to the graphics context is clipped. (see "Masking a Image by Clipping the Context.

Reference Http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_ Paths/dq_paths.html#//apple_ref/doc/uid/tp30001066-ch211-tpxref101

Transferred from: http://donbe.blog.163.com/blog/static/138048021201052093633776/

Paths (reprint)

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.