several important elements in the paths
Pointsvoid Cgcontextmovetopoint (Cgcontextref C, CGFloat x, cgfloat y); Specifies that a point becomes current Pointquartz tracks current points to perform a phase When the function is closed, the current point will change accordingly.
LinesSeveral functions related to void Cgcontextaddlinetopoint (Cgcontextref C, CGFloat x, cgfloat y); Create a line from current point to (x, y) and then current PO int will become (x, y) void Cgcontextaddlines (Cgcontextref C, const Cgpoint points[], size_t count), create multiple lines, such as points with two points, then draw two Line from current point to (X1,y1), then (X1,y1) to (x2,y2) and then current points into the points of the last dot
ArcsTwo methods create radians the first void Cgcontextaddarc (Cgcontextref C, CGFloat x,//center x coordinate cgfloat y,//x coordinate of the center of the Circle Cgflo At radius,//Circle radius cgfloat startangle,//Start Radian cgfloat endangle,//end radian int clockwise//0 for clockwise, 1 for 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). Another thing to note is that if there is already a subpath in the path, Then another effect of this function is to have a straight line from the current point to the beginning of the arc.
Second void Cgcontextaddarctopoint (Cgcontextref C, cgfloat x1,//x-coordinate of endpoint 1 cgfloat y1,//y-coordinate of endpoint 1 cgfloat x2,//x-coordinate of end 2 CGFloat y2,//y-coordinate of Endpoint 2 cgfloat radius//RADIUS); principle: First draw two lines, the two lines are the current points to (X1,y1) and (X1,y1) to (X2,Y2). This is the appearance of a (x 1,Y1) is a vertex of two rays, and then defines the radius length, which is perpendicular to two rays, so it can determine a circle, a better understanding of the look, but personally think the tangent point 1 location is wrong. Finally, when the function is finished, the current point is reset to (x2,y2). Another thing to note is that if a subpath is already present in the path, the other effect of this function is to have a straight line, from present point to (x1,y1 )
CurvesDraw 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 CP 2x,//Control point 2 x coordinate cgfloat cp2y,//Control point 2 y-coordinate cgfloat x,///end of line x coordinate cgfloat y//Line end y-coordinate); If the second control point (cp2x,cp2y) ratio (cp1x,cp1y is closer to current point, then a closed curve is formed two times the curve function void Cgcontextaddquadcurvetopoint (Cgcontextref C, CGFloat CPX,//control points x-coordinate CGF Loat cpy,//Control point y-coordinate cgfloat x,//The end of the line x coordinate cgfloat y//The end of the line y-coordinate); The function looks like the current point does not change, there is no specific test
ellipsesvoid Cgcontextaddellipseinrect (Cgcontextref context, CGRect rect//a rectangle); If the rectangle is a square, then the drawing is a circle execution function looks like the current point does not change No specific tests have been
rectanglesvoid Cgcontextaddrect (Cgcontextref C, CGRect rect); One-time draw of multiple rectangles void cgcontextaddrects (cgcontextref C, const CGRect rects[], size_t count); It is important to note that the draw rectangle has some special Have changed
Creating a PathCall function Cgcontextbeginpath Start creating the path, line call function Cgcontextmovetopoint set the starting point and start drawing the path you want to draw, notice the points: 1.Lines, arcs, and curves, are from current Point starts at 2. If you want to close a path, call the function Cgcontextclosepath to connect the current and starting points to 3. When painting arcs, Quartz draws a line from point to starting Point4. There is no third line when you draw a rectangle. 5. After you create 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. The correlation function and data type of the reuse path cgpathcreatemutable similar to cgcontextbeginpathcgpathmovetopoint similar to Cgcontextmovetopointcgpathaddlinetopoint similar to cgcontextaddlinetopointcgpathaddcurvetopoint similar to Cgcontextaddcurvetopointcgpathaddellipseinrect similar to cgcontextaddellipseinrectcgpathaddarc similar to Cgcontextaddarccgpathaddrect similar to cgcontextaddrectcgpathclosesubpath similar to Cgcontextclosepathcgpathrefcgmutablepathref uses the Cgcontextaddpath function to add a path to the graphics context void Cgcontextaddpath ( Cgcontextref context, cgpathref path);
Painting a PathStroking: Draw path filling: Closed area of the fill path parameters affecting stroking line widthvoid cgcontextsetlinewidth ( cgcontextref C, cgfloat width); Line join: The style of lines when turning, such as the sleek way void Cgcontextsetlinejoin ( cgcontextref c, cglinejoin join); line Cap: Styles at both ends of the line, such as the Smoothed void Cgcontextsetlinecap ( cgcontextref c, cglinecap Cap miter limit: When the line join mode is Miter join, this parameter will have an effect on void Cgcontextsetmiterlimit ( cgcontextref C, cgfloat limit); Line Dash pattern: dashed related void Cgcontextsetlinedash ( cgcontextref c, cgfloat phase, Const CGFloat lengths[], size_t count) stroke color spacevoid cgcontextsetstrokecolorspace ( & nbsp Cgcontextref c, cgcolorspaceref colorspace); Stroke colorvoid cgcontextsetstrokecolor ( cgcontextref c, const cgfloat components[]); void Cgcontextsetstrokecolorwithcolor ( cgcontextref c, Cgcolorref color); Stroke pattern (and transparency related) void Cgcontextsetstrokepattern ( cgcontextref c, cgpatternref pattern,& nbsp; const CGFloat components[]) stroking related functions strokes 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); decide whether to stroking or fillingvoid cgcontextdrawpath ( cgcontextref c, cgpathdrawingmode mode);
Filling a PathWhen 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 winding rule, 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 not filled, 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 ModesSet when a color is covered on another color, two colors how to mix the default way 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 ModeThis mode is the default mode, and the foreground map covers the background map.
Multiply Blend ModeWhen calling the function Cgcontextsetblendmode, use the parameter kcgblendmodemultiply. Mix two colors, the final color will be darker than the original two colors.
Screen Blend ModeUse parameters: Kcgblendmodescreen the foreground and background map color first, and then mix, the result of mixing the place brighter than the previous color, the foreground map is not mixed to the place to become white?
Overlay Blend ModeUse parameters Kcgblendmodeoverlay Bright depending on the background map
Darken Blend ModeKcgblendmodedarken
Lighten Blend ModeKcgblendmodelighten
Color Dodge Blend ModeKcgblendmodecolordodge
Color Burn Blend ModeKcgblendmodecolorburn
Soft Light Blend ModeKcgblendmodesoftlight
Hard light Blend ModeKcgblendmodehardlight
difference Blend ModeKcgblendmodedifference
exclusion Blend ModeKcgblendmodeexclusion
Hue Blend ModeKcgblendmodehue
saturation Blend ModeKcgblendmodesaturation
Color Blend ModeKcgblendmodecolor
luminosity Blend ModeKcgblendmodeluminosity
Clipping to a PathThis 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 |
use non 0 wrap Number Rule clip Current graphics context |
cgcontexteoclip |
Use parity rules to clip the current context |
cgcontextcliptorect |
Sets the intersection of a rectangular area and the current clipping region td> |
cgcontextcliptorects |
Sets the intersection of some rectangular areas and the current clipping region |
cgcontextcliptomask |
Maps a mask into the specified re Ctangle 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 an 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
Quartz official website Translation (reproduced)