csdn Blog original http://blog.csdn.net/zhenyu5211314/article/details/24230581
0 Cgcontextref context = uigraphicsgetcurrentcont ext (); Setting the context
1 Cgcontextmovetopoint Start drawing lines
2 Cgcontextaddlinetopoint Draw Straight line
4 Cgcontextaddellipseinrec t Draw an ellipse
4 Cgcontextsetlinecap Set line End shape
4 Cgcontextsetlinedash Draw Dashed line
4 Cgcontextaddrect Draw one side box
4 Cgcontextstrokerect Specify Rectangle
4 CGCONTEXTSTROKERECTWITHW Idth Specify the width of the rectangle line
4 Cgcontextstrokelinesegme nts Some straight lines
5 Cgcontextaddarc Draw already curved front two stores for center between two stores for the starting radian the last data is 0 clockwise draw 1 counterclockwise
5 Cgcontextaddarctopoint (context,0,0, 2, 9, 40);//Draw two lines from point to the Brother 1 points, from the Brother 1 point to the Brother 2 points of the line cut inside the circle
6 Cgcontextsetshadowwithco lor Setting shadows
7 Cgcontextsetrgbfillcolor This fill color
7 Cgcontextsetrgbstrokecol or Brush color settings
7 Cgcontextsetfillcolorspa CE color space fill
7 CGCONEXTSETSTROKECOLORSP Ace color space Brush Settings
8 Cgcontextfillrect complements the current fill color rect
8 Cgcontextsetalaha Transparency
9 CGCONTEXTTRANSLATECTM changing the canvas position
Cgcontextsetlinewidth set the width of the line
Draw Multiple Lines Cgcontextaddrects
Cgcontextaddquadcurvetop Oint Drawing Curve
Cgcontextstrokepath Start Drawing Pictures
Cgcontextdrawpath Set Drawing Mode
Cgcontextclosepath Close the current line
CGCONTEXTTRANSLATECTM (context, 0, rect.size.height); CGCONTEXTSCALECTM (Context, 1.0,-1.0); Invert canvas
Cgcontextsetinterpolatio nquality background Built-in color quality level
Cgimagecreatewithimagein Rect take a small image from the original image
17 writing of the string can be used NSString itself drawing Method-(Cgsize) Drawinrect: (cgrect) rect withfont: (Uifont *) font Linebreakmode: (uilinebreakmode ) Linebreakmode alignment: (uitextalignment) alignment; just write it in.
18 The function of zooming in and out of the picture is a little slow.
Uigraphicsbeginimagecont ext (newSize);
uiimage* newimage = Uigraphicsgetimagefromcu rrentimagecontext ();
Uigraphicsendimagecontex T ();
Cgcolorgetcomponents () returns the individual vertical and transparency of a color available as a read-only const float to receive a number of arrays
20 Draw picture Cgimageref image =cgimageretain (img. Cgimage);
Cgcontextdrawimage (Context, CGRectMake (10.0, Height-
100.0, 90.0, 90.0), image);
21 Implement the variable color Fill method cgcontextclip (context);
Cgcolorspaceref RGB = Cgcolorspacecreatedevice rgb ();
CGFloat colors[] =
{
204.0/255.0, 224.0/255.0, 244.0/255.0, 1.00,
29.0/255.0, 156.0/255.0, 215.0/255.0, 1.00,
0.0/255.0, 50.0/255.0, 126.0/255.0, 1.00,
};
Cggradientref gradient = Cggradientcreatewithcolo rcomponents
(RGB, colors, NULL, sizeof (colors)/(sizeof (COLORS[0)));
Cgcolorspacerelease (RGB);
Cgcontextdrawlineargradi ent (Context, Gradient,cgpointmake
(0.0,0.0), Cgpointmake (0.0,self.frame.size.height),
Kcggradientdrawsbeforest artlocation);
22 Note: Once you have finished drawing, you must
First use Cgcontextstrokepath to stroke the line, that is, the shape
Then use Cgcontextfillpath to fill the color inside the shape.
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
Cgcontextfillellipseinre CT
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
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.
Cgcontextsetblendmode Mix Two colors
Http://www.cocoachina.com/bbs/read.php?tid=75122&page=1
================================================================
Dashed
You need to use a function to draw a dashed line:
Cgcontextsetlinedash
This function requires four parameters:
- Context – This is not much to say
- Phase -we'll talk later.
- Lengths – Indicates how the dashed line is drawn alternately, see example
- The length of the count –lengths Array
- Cgcontextref context =uigraphicsgetcurrentcontext ();
- Cgcontextbeginpath (context);
- Cgcontextsetlinewidth (context, 2.0);
- Cgcontextsetstrokecolorwithcolor (context, [Uicolorwhitecolor]. Cgcolor);
- Float lengths[] = {10,10};
- Cgcontextsetlinedash (context, 0, lengths,2);
- Cgcontextmovetopoint (context, 10.0, 20.0);
- Cgcontextaddlinetopoint (context, 310.0,20.0);
- Cgcontextstrokepath (context);
- Cgcontextclosepath (context);
The value of lengths {10,10} indicates that 10 points are drawn first, and then 10 points are skipped, so repeatedly,
If the lengths value is changed to {10, 20, 10}, then 10 points are drawn, 20 points are skipped, 10 points are drawn, 10 points are skipped, 20 points are drawn, so repeated,
Note the value of Count equals the length of the lengths array
The phase parameter indicates how many points are skipped when the first dashed line is drawn, for example:
- Float lengths[] = {10,5};
- Cgcontextsetlinedash (context, 0, lengths, 2);
- Cgcontextmovetopoint (context, 0.0, 20.0);
- Cgcontextaddlinetopoint (context, 310.0, 20.0);
- Cgcontextstrokepath (context);
- Cgcontextsetlinedash (Context, 5, lengths, 2);
- Cgcontextmovetopoint (context, 0.0, 40.0);
- Cgcontextaddlinetopoint (context, 310.0, 40.0);
- Cgcontextstrokepath (context);
- Cgcontextsetlinedash (context, 8, lengths, 2);
- Cgcontextmovetopoint (context, 0.0, 60.0);
- Cgcontextaddlinetopoint (context, 310.0, 60.);
- Cgcontextstrokepath (context);
Show:
Because the lengths value is {10,5}, the first line is drawn 10, skips 5, and draws repeatedly.
The phase value of the second line is 5, then the first draw "10 minus 5", then skip 5, Draw 10, draw repeatedly.
The third gives the same, draw 2 first, then skip 5, so repeat.
Cgcontextsetstrokecolorw Ithcolor (Mycontext, [Uicolor Blackcolor]. Cgcolor);
Cgcontextsetlinedash (mycontext,phase,lengths,2);
Cgcontextclosepath (Mycontext);
Cgcontextstrokepath (Mycontext);
================================================================
Tangent
-(void) DrawRect: (cgrect) Rect {
Cgcontextref context = Uigraphicsgetcurrentcontext ();
Cgcontextsetlinewidth (context, 2.0);
Cgcontextsetstrokecolorwithcolor (context, [Uicolor Bluecolor]. Cgcolor);
Cgcontextmovetopoint (context, 100, 100);
Cgcontextaddarctopoint (context, 100,200, 300,200, 100);
Cgcontextstrokepath (context);
}
================================================================
-(void) DrawRect: (cgrect) Rect {
Cgcontextref context = Uigraphicsgetcurrentcontext ();
Cgcontextsetlinewidth (context, 2.0);
Cgcontextsetstrokecolorwithcolor (context, [Uicolor Bluecolor]. Cgcolor);
CGRect rectangle = CGRectMake (60,170,200,80);
Cgcontextaddellipseinrect (context, rectangle);
Cgcontextstrokepath (context);
}
================================================================
-(void) DrawRect: (cgrect) Rect {
Cgcontextref context = Uigraphicsgetcurrentcontext ();
Cgcontextsetlinewidth (context, 2.0);
Cgcontextsetstrokecolorwithcolor (context, [Uicolor Bluecolor]. Cgcolor);
Cgcontextmovetopoint (context, 10, 10);
Cgcontextaddcurvetopoint (context, 0, 50, 300, 250, 300, 400);
Cgcontextstrokepath (context);
}
================================================================
-(void) DrawRect: (cgrect) Rect {
Cgcontextref context = Uigraphicsgetcurrentcontext ();
Cgcontextsetlinewidth (context, 2.0);
Cgcontextsetstrokecolorwithcolor (context, [Uicolor Bluecolor]. Cgcolor);
Cgcontextmovetopoint (context, 10, 200);
Cgcontextaddquadcurvetopoint (context, 150, 10, 300, 200);
Cgcontextstrokepath (context);
}
================================================================
-(void) DrawRect: (cgrect) Rect {
Cgcontextref context = Uigraphicsgetcurrentcontext ();
Cgcontextsetlinewidth (context, 5.0);
Cgcontextsetstrokecolorwithcolor (context, [Uicolor Bluecolor]. Cgcolor);
CGFloat dasharray[] = {2,6,4,2};
Cgcontextsetlinedash (Context, 3, Dasharray, 4);
Cgcontextmovetopoint (context, 10, 200);
Cgcontextaddquadcurvetopoint (context, 150, 10, 300, 200);
Cgcontextstrokepath (context);
}
iOS Development--Drawing (Cgcontext)