Review iOS diary drawing Advanced 14- [2020]

preamble

Mainly based on a record of more advanced graphics knowledge

text

Matrix operations
rotation:
CGContextRotate (context, M_PI_4)
Zoom:
CGContextScaleCTM (context, sx the zoom magnification, sy the zoom magnification);
translation:
CGontextTranslateCTM (context, x, y);
have effect until the path into context.

Stack
CGContextSaveGState (context); // save the color state of the context width
CGCotextREstoreGState (context); // restore previous context

Memory management
CGPathRelease (path object) // freed path object
CGRElease (path object) // freed path object

Draw text
NSString * te = @ "test";
[TE drawAtPoints: from a certain point on withAttributes: @ {NSFontAttributeName: UIFont systemFontOfSize : 30}]; // do not wrap
[te drawInRect: area size plus a certain point withAttributes: nil]; // can wrap
// withAttributes incoming dictionaries are written on various parameters of the font, for nil

Image rendering
the UIImage * Image = [the UIImage the imageNamed: @ "XXX"];
[Image drawAtpoints: beginning from a point]; //
[Image drawInRect: add a point size area]; // draw

Rendering context clipping region
, if desired create a circular image
obtained first picture object, before this step requires a cut-out area in need
CGContextAddAcr () // draw a circle
CGCOntextClip () // clipping path only after cutting circle display content // crop context display area
image drawInRect: display image is stretched

Picture type context
1. Open
UIGraphicsBeginImageContext (Size size);
or parameterized: WithOptions this general use, the adjustable parameters of the back multiple pixel
2. Obtain current context
CGContextRef UIGrapicsGetCurrentContext CTX = ();
3. stitching path
CGCotextMoveToPoint (ctx, 50, 50);
CGCOntextAddLineToPoint (CTX, 100,100);
4. rendering
CGContextStrokePath (CTX);
// get the context of the subject image by
the UIImage * = UIGraphicsGetImageFromCurrentImagecontext image ();
// Close
UIGraphicsEndImageContext ();

Image watermark:
obtaining picture image
to open the picture context
[image drawAtPoins: 0,0] // draw the picture in the context
NSString * str = @ "Watermark"
[str drawAtPoints: the X-, the y-withAttributes:]. // text written in context in
to get the final picture
close the picture context

Published 15 original articles · won praise 0 · Views 2555

Guess you like

Origin blog.csdn.net/u014270781/article/details/105350365