When using quartz paint in iOS, the first step is to get the canvas (the graphics context) and then do the various things on the canvas. you can see how many context types you can create by looking at the CoreGraphics.h header file first.
#include <CoreGraphics/CGBase.h> #include <CoreGraphics/CGAffineTransform.h> #include <coregraphics/ cgbitmapcontext.h> #include <CoreGraphics/CGColor.h> #include <CoreGraphics/CGColorSpace.h> #include <CoreGraphics/CGContext.h> #include <CoreGraphics/CGDataConsumer.h> #include <coregraphics/ cgdataprovider.h> #include <CoreGraphics/CGError.h> #include <CoreGraphics/CGFont.h> #include < coregraphics/cgfunction.h> #include <CoreGraphics/CGGeometry.h> #include <coregraphics/cggradient.h > #include <CoreGraphics/CGImage.h> #include <CoreGraphics/CGLayer.h> #include <coregraphics/ cgpdfarray.h> #include <CoreGraphics/CGPDFContentStream.h> #include <coregraphics/cgpdfcontext.h># Include <CoreGraphics/CGPDFDictionary.h> #include <CoreGraphics/CGPDFDocument.h> #include < coregraphics/cgpdfobject.h> #include <CoreGraphics/CGPDFOperatorTable.h> #include <coregraphics/ Cgpdfpage.h> #includE <CoreGraphics/CGPDFScanner.h> #include <CoreGraphics/CGPDFStream.h> #include <coregraphics/ cgpdfstring.h> #include <CoreGraphics/CGPath.h> #include <CoreGraphics/CGPattern.h> #include < Coregraphics/cgshading.h>
As you can see, the contexts you can create include:
// Image cgcontextref cgbitmapcontextcreate // Layer (UIView) cgcontextref Cglayergetcontext // PDF Type Cgcontextref cgpdfcontextcreate
Let's look atthe UI Graphics.h this header file, which already provides the methods used by the 3 context-created packages for uikit, in normal cases, using themethods in the UI Graphics, and the canvas has been rotated in coordinates.
Uikit_extern cgcontextref uigraphicsgetcurrentcontext (void) cf_returns_not_retained;
Represents a weak reference type, which is used directly without releasing.
Uigraphicsbeginimagecontext (self.bounds.size); Cgcontextref Context=Uigraphicsgetcurrentcontext (); Cgcontextsetrgbfillcolor (Context,1,0,0,1); Cgcontextsetrgbstrokecolor (Context,0,1,0,1); Cgcontextfillrect (Context, CGRectMake (0, -, -, -)); NSString*text=@"text"; Uifont*font=[uifont systemfontofsize: -]; [Text Drawatpoint:cgpointmake (0, $) withAttributes:font.fontDescriptor.fontAttributes]; UIImage*img=[uiimage imagenamed:@"gg.jpg"]; [img Drawinrect:cgrectmake (0, -, -, -)]; Cgimageref cgimg=cgbitmapcontextcreateimage (context); UIImage*resultimg =[UIImage imagewithcgimage:cgimg]; Cgimagerelease (cgimg);
Quartz 2D usage in iOS two: creating a canvas