Notes for programming with quartz-1st

Source: Internet
Author: User

 

The context canvas can be a window printer bitmap display filling filled with alpha (opacity) opacity 1 is opacity 0 transparency this attribute determines whether the following picture opaque opacity stroking draws a border in the rectangle border (this border is infinite thin) the two sides draw a line with the width cgcontextref context = uigraphicsgetcurrentcontext (); // obtain the histogram (context, 1.0, 0.0, 0.0, 1.0) in the drawrect method // set the color cgcontextfillrect (context, ourrect); // fill cgcontextsetrgbstrokecolor (context, 0.482, 0.62, 0.871, 1.0); cgcont Extstrokerectwithwidth (context, ourrect, 3.0 ); // set the Border width. The border is drawn on the 2-side. Therefore, after the frame is filled, the inside border is overwritten by cgcontexttranslatectmcgcontextscalectmcgcontextrotatectmarbitrary. Any path of any image is a sequence of path. lines and curves that make up a shape, and then padding Ming painting operations on that pathcgcontextbeginpath Replace the existing path replaces any existing path in the context with an empty pathcgcontextmovetop Oint path start point establishes the first point on the path and makes that the current pointcgcontextaddlinetopoint draw line add a line segment from the existing current point to the point passed to cgcontextadd-linetopoint cgcontextclosepath draw a line between them to complete a shape. this function adds a straight line segment from the current point to the initial point on the pathcgcontextdrawpath will not generate any image draw, and this method will also Clear Path. Actually paint the stroked, filled, and stroked-and-filled paths, also clears the path from the contextkcgpathfill kcgpathstroke kcgpathfillstroke // This type of fill-then-stroke operation is so common that quartz defines the special defined painting mode used destroy (context, 200.0, 0.0); the coordinate offset X axis is 200 forward, and the draw is adjusted according to the changed coordinate drawing completed MED after calling cgcontexttranslatec TM takes place in the transformed coordinate system. cgcontextsetlinewidth sets the width of the stroke cgcontextsavegstate (context); keeps the current state of context cgcontextrestoregstate (context); returns the context state cgcontextrotatectm (context, rotateangle ); the clockwise unit of the rotating coordinate system is radians. The circle is 2 * m_pi // The drawing point line cgcontextsetlinedash (context, 0 ., lengths, 4); // specify the Starting Point Coordinate for the 2nd parameters, for example, 18 (lengths [0] + lengths [1]), so the first point is actually 5 (lengths [2]), and the 4th parameters use several Len Gths (must be less than the total length of length) float lengths [6] = {12.0, 6.0, 5.0, 6.0, 5.0 }; clipping crop setting up a clipping area requires creating a path to clip to, then calling the function cgcontextclip to tell quartz to constrain drawing to the area inside that path. specify a path when cropping, and then execute the cropping method cgcontextbeginpath (context); cgcontextaddrect (context, ourrect); cgcontextclip (context) cgcontextcliptorect // clipping to a rec Tangle specified by a cgrectcgcontextaddarc (context, circlecenter. x, circlecenter. y, circleradius, startingangle, endingangle, 0); Circle, parameter: Center, radius, start angle, end angle, whether the last one should clockwise cgcontextscalectm (context, 1,-1 ); scale down coordinate-1 is the reverse coordinate Y axis window contextbitmap graphics contextpdf graphics contextpostscript contextglcontext contextyou can perform the same drawing without regard to the type of context that you are drawing To. you do the drawing and quartz takes care of converting that drawing into the best representation for the device, or context, into which you are drawing. device independence is one of the most powerful features of quartz. using the nsimage class to draw images can result in the creation of multiple cgimage objects when drawing a given image. this produces larger PDF doc-uments since drawing Same nsimage to a given PDF context multiple times does not produce a single copy of the image data. in addition, JPEG image data is not treated specially by nsimage; therefore, during PDF genera-tion, uncompressed data is written to the PDF documentuser space and device spacefor a PDF context, the size of a default user space unit is 1/72 of an inch, a unit of measure called a point. for a prin Ting context, 1 user space unit is a point, regardless of the Resolution of the output device used for printing. this means that for a printing context corresponding to a 300-dpi raster printer, 1 user space unit is 1/72 of an inch, So 72 user space units equals 1 inch or 300 device pixels. the term point has its origins in the printing industry where historically the size of a printer point was ap Proximately 1/72 of an inch. quartz has adopted the same definition of a point as the postscript and PDF imaging models with 1 point being exactly 1/72 of an inch. because quartz drawing calltake user space coordinates as parameters and the output device coordinates are in device space, quartz must map all user space coordinates into device space coordinates as part of its rendering. by providing An abstract user space coordinate system and taking care of the mapping of those coordinates onto the output device, quartz provides a device-independent COOR-dinate system. the coordinate mapping extends med by quartz also provides the flexibility of additional user space transformations, such as the translation, rota-tion, and scaling of coordinates as seen in the examples in "quartz 2D drawing Basics "(page 15 ). current transformation matrix // ctmcgaffinetransform // This data structure consists of six floating-point values: A, B, C, D, TX, and Ty. x' = A * x + C * Y + txy' = B * x + D * Y + ty in an asymmetric coordinate scaling, the next rotation will create a skewed coordinate system nonuniform scaling of a coordinate system, followed by a rotation, produces a skew or shear to the coordinate axes // Alpha is 22.5 degrees and beta is 15 degrees. floa T alpha = m_pi/8, Beta = m_pi/12; cgaffinetransform skew = cgaffinetransformmake (1, Tan (alpha), Tan (Beta), 1, 0, 0 ); cgcontextconcatctm (context, skew); All quartz paintings are divided into three types: line, image, and text. All quartz drawing falls into of one of three fundamental categories: line art (graphics that consist of paths that are filled, stroked, or both), Sampled images, and text. quadratic quadratic cubic cube path can be open, closed, and direction. A path can have many subpaths which are not necessarily connected. cgcontextmovetopoint creates a subpath cgcontextsetrgbstrokecolor (context, 0, 0, 1, 0.7); cgcontextbeginpath (context); cgcontextmovetopoint (C Ontext, 0, 0); cgcontextaddlinetopoint (context, 30, 40); cgcontextmovetopoint (context,-20, 10); cgcontextaddlinetopoint (context, 100, 70); cgcontextdrawpath (context, kcgpathstroke); therefore, all the paths are created by the following five basic methods: All paths in quartz can be constructed using one or more of the following five basic path construction primitive functions, I cgcontextmovetopoint begins a new subpath in the current path. I cgcontex Taddlinetopoint adds a straight line segment to the current path. I cgcontextaddcurvetopoint adds a cubic B 'curve segment to the current path. I cgcontextaddquadcurvetopoint adds a quadratic B 'curve segment to the current path. I cgcontextclosepath ends the current path. // draw a line cgcontextbeginpath between the current point and the start point. clear pathcubic bézr curves are defined by two endpoints together with two Addition Al control points. P (t) = (1-T) 3P0 + 3 T (1-T) 2C1 + 3t2 (1-T) C2 + t3p1cgcontextaddcurvetopoint (context, c1.x, c1.y, c2.x, c2.y, p1.x, p1.y); quadratic B 'curve are defined by two endpoints and a single control pointp (t) = (1-T) 2P0 + 2 T (1-T) c + t2p1cgcontextaddquadcurvetopoint (<# cgcontextref C #>, <# cgfloat cpx #>, <# cgfloat CPY #>, <# cgfloat X # >,< # cgfloat y #>) cgcontextclosepath indicates the start point and end point during execution. If they are not together, a line will be added to connect them. Quartz subpaths are either open or closed. A closed subpath has its initial point connected to the last point on the subpath. the function cgcontextclosepath connects the last point on the subpath with the initial point on the beginning // The result-ing subpath is open; you must call cgcontextclosepath if you want to close it. if Then, a line will be connected to the starting point of this vertex and the circle until wide width // line width is affected by the scaling aspects of the ctmline join // three different types of joins-Miter, round, or bevel kcglinejoinmiter, KC Glinejoinround, or kcg-linejoinbevelline cap // butt, square, or rounded kcglinecap-butt, kcglinecapsquare, or javasdashfilling A pathfilling fills the path, but it is difficult to judge the internal complexity of the path. quartz defines two distinct rules to determine the interior of a path. you choose which rule to apply when filling a path-the non-zero winding number rule or the even-odd (kcgpatheofillstroke) Rule cgpathrefcgmut Ablepathref Path = cgpathcreatemutable (); cgpathaddarc (path, & thetransform, 0 ., 0 ., 45 ., 0 ., 2 * m_pi, false); cgpathclosesubpath (PATH); gradient colors // aspect in the path, color components are not included, transparency and global transparency // quartz supports A global Alpha, applied to all drawinggraphics state fill and stroke colors current transformation matrix (CTM) the clipping area, the font, and more than a dozen other parameterscolor spaces RGB uses three-red, green, and blue CMYK uses four-cyan, magenta, yellow, and blackquartz color spaces fall into three basic categories calibrated color spaces specify color is reproduc-ble sans ss a wide Ra Nge of output devices. iccbased, calibratedgray, calibratedrgb, and LAB color spaces. device-dependent color spaces devicegray, devicergb, and devicecmyk color spaces special color spaces pattern Color Space indexed color spaceintrinsic comes with quartz also uses the current fill color space and fill color component values when painting images without intrinsic extends implicitly uses The devicergb color space specified devicergb = random (); float opaquered [] = {0.663, 0.0, 0.031, 1.0} cgcontextsetfillcolorspace (context, thecolorspace); cgcontextsetfillcolor (context, opaquered ); fill alpha = 0.25 global alpha = 0.5 valid tive alpha =. 125 cgdataprovidercreatewithurlcgdataprovidercreatewithdatacgdataprovidercreatecgdataprovidercreat Required bytes url = .....; Cgrect jpgrect; cgimageref jpgimage = NULL; cgdataproviderref jpgprovider = Response (URL); jpgimage = Response (jpgprovider, null, true, kcgrenderingintentdefault); Response (jpgprovider ); jpgrect = cgrectmake (0 ., 0 ., cgimagegetwidth (jpgimage)/4, cgimagegetheight (jpgimage)/4); cgcontextdrawimage (context, jpgrect, jpgimage); Image Mask, masking image, and maskstenpencil template Image Mask is a template image, just like a template on a White Paper, and then spray paint, the paper will leave the marks of the terms Image Mask, masking image, and mask are interchange-able terms to describe an image whose sample values indicate a percentage of paint to apply but not the color of the paint itself. such an image is sometimes called a stencel mask because the mask does not itself have any intrinsic color; instead, color "pours" through the stencel. an Image Mask has only one compo-nent value, the coverage value.1bit mask only shows on/off, 8 bit can show color depth, an image mask can be 1, 2, 4, or 8 bits per sample. A sample value that decodes to 0 allows paint to go through it-it's the "hole" in the stencel. A sample value that decodes to 1 doesn't allow paint through-it's the solid part of the stencel. A 1-bit mask, by definition, has only "On/Off" options-0 or 1. deeper masks, such as an 8-bit mask, can contain intermediate values (0 <x <1) that specify grada-tions of paint that get through the mask, with lower values allowing more paint than higher values. quartz provides three masking devices that can control how pixels are painted-image masks, images that are used for the purpose of masking another image, and masking colors. textcgcontextselectfont sets both the font and the font grouping sets only the fonttext space quartz text is drawn in a special coordinate system called text spacetext matrix an affine transform that maps text space coordinates into user space coordinates

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.