------------------------------ rotate pan zoom ----------------------------------
-(void) DrawRect: (cgrect) rect
{
// Get context
Cgcontextref CTX = Uigraphicsgetcurrentcontext ();
//Current graphics state ' s transformation Matrix
// zoom
CGCONTEXTSCALECTM (CTX, 0.5, 0.5);
// panning
//CGCONTEXTTRANSLATECTM (CTX, N-max);
// rotate
//CGCONTEXTROTATECTM (CTX, m_pi_4);
// stitching paths Add paths to the context at the same time
// round
Cgcontextaddarc (CTX, 0, 2 * m_pi, 1);
// line
Cgcontextmovetopoint (CTX, 0, 0);
Cgcontextaddlinetopoint (CTX, + );
// Set line width
Cgcontextsetlinewidth (CTX, a);
// rendering
Cgcontextstrokepath (CTX);
}
--- rotate zoom pan
operation to rotate and pan scale The graphics context ( matrix operation )
Zoom
first parameter : the context that needs to be scaled
second parameter : scale of X-axis scaling
third parameter : scale of the y-axis scaling
CGCONTEXTSCALECTM (CTX, 1, 0.5);
panning
first parameter : the context that needs to be panned
second parameter : offset of x-axis
third parameter : offset of the y-axis
CGCONTEXTTRANSLATECTM (CTX, ,, );
Rotate
first parameter : the context that needs to be rotated
second parameter : angle of clockwise rotation
CGCONTEXTROTATECTM (CTX, m_pi_4);
---The graphics context stack
The graphics context stack is just the save state information ( style )
Saving state information
Cgcontextsavegstate (CTX);
Restore status information
Cgcontextrestoregstate (CTX);
---quartz2d memory management
If you include the Create copy keyword, remember to release
release 1
Cgpathrelease (path);
Release 2
Cfrelease (path);
--- drawing text
Draw - draw from (0,0) point
[str Drawatpoint:cgpointzero withattributes:dict];
Draw - draws to the specified area
[Str drawinrect:rect withattributes:nil];
Attributename-key in the NSAttributeName.h under UIKit .
Personal advice to remember one of them
Shadow
nsshadow* s = [[Nsshadow alloc] init];
S.shadowoffset = Cgsizemake (+ ); // offset
S.shadowblurradius = 0; //The smaller the less blurred
S.shadowcolor = [Uicolor Yellowcolor]; // color of shadow
If a text has a background color, the shaded section does not display text
--- drawing pictures
Draw - draw from a point
[Image Drawatpoint:cgpointzero];
Draw - draw to an area
[Image Drawinrect:rect];
Draw - tile
[Image Drawaspatterninrect:rect]; // You can consider setting a background image for a view
--- the area that the clipping context displays
premise : draw a graphic
crop a picture
Cgcontextclip (CTX);
tell the system that it has this shape to crop the image and then display it.
The so-called clipping is not to cut out the context is simply to cut out the area you want to display it !!!
---bitmap context
Create context ( picture )
Uigraphicsbeginimagecontext (Cgsizemake (+ ));
Create Context ( size , opacity , scale : 0)
Uigraphicsbeginimagecontextwithoptions (Cgsizemake (), NO, 0);
Close Context
Uigraphicsendimagecontext ();
get a picture from the graphics context of a picture
uiimage* image = Uigraphicsgetimagefromcurrentimagecontext ();
Save to Sandbox
nsstring* path = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES) [0] ;
Path = [path stringbyappendingpathcomponent:@ "Xx.png"];
convert image to nsdata type
nsdata* data = uiimagepngrepresentation (image);
NSLog (@ "%ld", data.length);
It is then written to the sandbox using the data object write to File
[Data Writetofile:path atomically:YES];
Rotate Pan Zoom