iOS Drawing summary

Source: Internet
Author: User

iOS Drawing summaryCategory: Ios_ drawing 2012-11-28 11:21 347 people reading reviews (0) favorite reports Http://www.cnblogs.com/yuanxiaoping_21cn_com/archive/2012/03/24/2415706.html0 Cgcontextref context = uigraphicsgetcurrentcontext (); Setting the context
1 Cgcontextmovetopoint Start drawing lines
2 Cgcontextaddlinetopoint Draw Straight line

4 Cgcontextaddellipseinrect 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 Cgcontextstrokerectwithwidth Specify the width of the rectangle line
4 Cgcontextstrokelinesegments 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 Cgcontextsetshadowwithcolor Setting Shadows
7 Cgcontextsetrgbfillcolor This only fillsColor
7 Cgcontextsetrgbstrokecolor Brush Color settings
7 Cgcontextsetfillcolorspace Color Space fill
7 Cgconextsetstrokecolorspace 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
Cgcontextaddquadcurvetopoint Draw Curve
Cgcontextstrokepath Start DrawingImage
Cgcontextdrawpath Set Drawing Mode
Cgcontextclosepath Close the current line
CGCONTEXTTRANSLATECTM (context, 0, rect.size.height); CGCONTEXTSCALECTM (Context, 1.0,-1.0); Invert canvas
Cgcontextsetinterpolationquality background built-in color quality level
Cgimagecreatewithimageinrect take a small picture from the original image

17The writing of the string can be used in the drawing method of the NSString itself-(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.
Uigraphicsbeginimagecontext (newSize);
uiimage* newimage = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();

Cgcolorgetcomponents () returns the individual colors of the straight and transparent can be read-only const float to receive is aArray

20 Painting Pictures CgimagerefImage=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 = Cgcolorspacecreatedevicergb ();
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 = cggradientcreatewithcolorcomponents
(RGB, colors, NULL, sizeof (colors)/(sizeof (COLORS[0)));
Cgcolorspacerelease (RGB);
Cgcontextdrawlineargradient (Context, Gradient,cgpointmake
(0.0,0.0), Cgpointmake (0.0,self.frame.size.height),
Kcggradientdrawsbeforestartlocation);

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
Cgcontextfillellipseinrect
Fills the ellipse in the specified rectangle
Cgcontextdrawpath
TwoThe parameter determines the fill rule, Kcgpathfill represents the rule with a non-0 number, the Kcgpatheofill is represented by 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

iOS Drawing summary

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.