iOS開發CoreGraphics核心圖形框架之二——深刻理解圖形上下文

iOS開發CoreGraphics核心圖形框架之二——深刻理解圖形上下文

1、引言

      在上一篇博客中,介紹了有關CGPath繪製路徑的相關方法,其中在View視圖的drawRect方法中,已經使用過上下文將Path路徑繪製到當前視圖上,上一篇博客只是拋磚引玉,本片博客將更深刻的介紹下有關上下文的更多內容。關於接胡搜啊CGPath應用的博客地址以下:前端

iOS開發CoreGraphics核心圖形框架之一——CGPath的應用:http://www.javashuo.com/article/p-czajqrsj-cd.html框架

2、關於圖形上下文Graphics Context

      GraphicsContext對於開發者來講是徹底透明的,開發者不須要關心其實現,也不須要關心其繪製方式,開發者只須要將要繪製的內容傳遞給圖形上下文,由圖形上下文來將內容繪製到對應的目標上。這個目標能夠是視圖,窗口,打印機,PDF文檔或者位圖對象。須要注意,繪製的順序在CoreGraphics框架中十分重要,若是後繪製的內容和先繪製的內容有位置衝突,後繪製的內容將覆蓋先繪製的內容。函數

    特定的上下文用於將內容繪製到特定的輸出源上,CoreGraphics中提供以下幾種圖形上下文:字體

1.位圖圖形上下文:位圖圖形上下文用於將RGB圖像,GMYK圖像或者黑白圖像繪製到一個位圖(bitmap)對象中。url

2.PDF圖形上下文:PDF圖形上下文能夠幫助開發者建立PDF文件,將內容繪製進PDF文件中,其與位圖上下文最大的區別在於PDF數據能夠保存多頁圖像。spa

3.窗口上下文:用於OS系統中的窗口繪製。.net

4.圖層上下文:用於將內容繪製在Layer圖層上。code

5.打印上下文:使用Mac打印功能時,此上下文用於將內容繪製在打印輸出源上。component

3、在UIKit框架中操做圖形上下文

    在UIKit框架中有一個UIGraphics頭文件,其中封裝了許多對當前圖形上下文進行操做的方法。首先任何UIView和其子類的視圖控件都有一個drawRect方法,當視圖將要被繪製時會調用這個方法,在drawRect方法中開發者能夠獲取到當前視圖的圖形上下文,經過這個圖形上下文能夠對視圖進行自定義的繪製。UIGraphics頭文件中定義的以下方法能夠對當前的圖形上下文進行操做:orm

//這個方法用於獲取當前的圖形上下文
UIKIT_EXTERN CGContextRef __nullable UIGraphicsGetCurrentContext(void) CF_RETURNS_NOT_RETAINED;
//這個方法用於將某個圖形上下文對象壓入棧中 使其變爲當前的圖形上下文
UIKIT_EXTERN void UIGraphicsPushContext(CGContextRef context);
//這個方法用於將當前的圖形上下文出棧 當前的圖形上下文始終是棧頂的圖形上下文
UIKIT_EXTERN void UIGraphicsPopContext(void);

須要注意,上面的UIGraphicsPushContext()與UIGraphicsPopContext()方法經常使用於切換當前的圖形上下文。

//下面這兩個方法用於向當前的圖形上下文中填充矩形 
UIKIT_EXTERN void UIRectFillUsingBlendMode(CGRect rect, CGBlendMode blendMode);
UIKIT_EXTERN void UIRectFill(CGRect rect);
//下面這兩個方法用於向當前的圖形上下文中繪製矩形邊框
UIKIT_EXTERN void UIRectFrameUsingBlendMode(CGRect rect, CGBlendMode blendMode);
UIKIT_EXTERN void UIRectFrame(CGRect rect);
//這個方法用於裁剪當前的圖形上下文的繪製區域
UIKIT_EXTERN void UIRectClip(CGRect rect);

上面方法中的CGBlendMode參數用於設置圖像的混合模式,意義列舉以下:

typedef CF_ENUM (int32_t, CGBlendMode) {
    //在背景圖像之上繪製原圖像
    kCGBlendModeNormal,
    //將背景與原圖像進行混合
    kCGBlendModeMultiply,
    //將背景與原圖像進行逆向混合
    kCGBlendModeScreen,
    //覆蓋原圖像 同時保持背景陰影
    kCGBlendModeOverlay,
    //進行灰度複合
    kCGBlendModeDarken,
    //進行亮度複合
    kCGBlendModeLighten,
    //複合時 黑色不進行復合
    kCGBlendModeColorDodge,
    //複合時 白色不進行復合
    kCGBlendModeColorBurn,
    //複合時 根據黑白色值比例進行復合
    kCGBlendModeSoftLight,
    kCGBlendModeHardLight,
    //複合時 將原圖像中有關背景圖像的色值去除
    kCGBlendModeDifference,
    //與kCGBlendModeDifference相似 對比度更低
    kCGBlendModeExclusion,
    //使用原圖像的色調與飽和度
    kCGBlendModeHue,
    //同kCGBlendModeHue 純灰度的區域不產生變化
    kCGBlendModeSaturation,
    //同kCGBlendModeHue 保留灰度等級
    kCGBlendModeColor,
    //與kCGBlendModeHue效果相反
    kCGBlendModeLuminosity,
    
    //下面這些枚舉定義了MacOS中圖像複合的計算方式 
    //R 結果  
    //S 原圖像
    //D 背景圖像
    //Ra Sa Da爲帶透明alpha通道

    kCGBlendModeClear,                  /* R = 0 */
    kCGBlendModeCopy,                   /* R = S */
    kCGBlendModeSourceIn,               /* R = S*Da */
    kCGBlendModeSourceOut,              /* R = S*(1 - Da) */
    kCGBlendModeSourceAtop,             /* R = S*Da + D*(1 - Sa) */
    kCGBlendModeDestinationOver,        /* R = S*(1 - Da) + D */
    kCGBlendModeDestinationIn,          /* R = D*Sa */
    kCGBlendModeDestinationOut,         /* R = D*(1 - Sa) */
    kCGBlendModeDestinationAtop,        /* R = S*(1 - Da) + D*Sa */
    kCGBlendModeXOR,                    /* R = S*(1 - Da) + D*(1 - Sa) */
    kCGBlendModePlusDarker,             /* R = MAX(0, (1 - D) + (1 - S)) */
    kCGBlendModePlusLighter             /* R = MIN(1, S + D) */
};

下面這些方法用於操做位圖圖形上下文:

//這個方法會建立一個位圖圖形上下文 並將其push進圖形上下文棧中 size參數設置圖像的大小
UIKIT_EXTERN void     UIGraphicsBeginImageContext(CGSize size);
//方法同上,其中opaque參數設置是否爲不透明的 scale設置縮放因子
UIKIT_EXTERN void     UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale) NS_AVAILABLE_IOS(4_0);
//這個方法用於將當前的位圖圖形上下文內容畫成UIImage對象
UIKIT_EXTERN UIImage* __nullable UIGraphicsGetImageFromCurrentImageContext(void);
//結束位圖圖形上下文的編輯 會POP出棧
UIKIT_EXTERN void     UIGraphicsEndImageContext(void);

咱們能夠經過代碼來畫一個簡單的UIImage圖像,示例以下:

- (void)viewDidLoad {
    [super viewDidLoad];
    //建立位圖圖形上下文 設置大小爲200*200
    UIGraphicsBeginImageContext(CGSizeMake(200, 200));
    //獲取到當前圖形上下文
    CGContextRef ref = UIGraphicsGetCurrentContext();
    //裁剪其進行繪製的尺寸爲100*100
    UIRectClip(CGRectMake(0, 0, 100, 100));
    //設置線條顏色
    [[UIColor redColor] setStroke];
    //設置填充顏色
    [[UIColor grayColor] setFill];
    //設置邊框寬度
    CGContextSetLineWidth(ref, 10);
    //進行填充
    UIRectFill(CGRectMake(0, 0, 100, 100));
    //進行邊框繪製
    UIRectFrame(CGRectMake(0, 0, 200, 200));
    //拿到UIImage實例
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    //結束位圖上下文編輯
    UIGraphicsEndImageContext();
    //將UIImage展現到界面上
    UIImageView * imageView = [[UIImageView alloc]initWithImage:image];
    imageView.contentMode = UIViewContentModeCenter;
    imageView.frame = CGRectMake(100, 100, 200, 200);
    [self.view addSubview:imageView];
}

效果以下圖所示:

與操做PDF圖形上下文的相關方法以下:

//這個方法用於建立一個PDF圖形上下文 將其入棧 做爲當前的圖形上下文  
/*
其中path爲PDF文件寫入的路徑
bounds爲PDF文檔的尺寸
decumentInfo地點爲設置PDF文檔信息 後面會介紹
*/
UIKIT_EXTERN BOOL UIGraphicsBeginPDFContextToFile(NSString *path, CGRect bounds, NSDictionary * __nullable documentInfo) NS_AVAILABLE_IOS(3_2);
//這個方法用於穿件一個PDF圖形上下文 可是將PDF內容寫成Data數據 參數意義同上
UIKIT_EXTERN void UIGraphicsBeginPDFContextToData(NSMutableData *data, CGRect bounds, NSDictionary * __nullable documentInfo) NS_AVAILABLE_IOS(3_2);
//結束PDF圖形上下文的編輯 將其出棧
UIKIT_EXTERN void UIGraphicsEndPDFContext(void) NS_AVAILABLE_IOS(3_2);
//這個方法用於將當前的PDF圖形上下文新開一頁內容
UIKIT_EXTERN void UIGraphicsBeginPDFPage(void) NS_AVAILABLE_IOS(3_2);
//同上
UIKIT_EXTERN void UIGraphicsBeginPDFPageWithInfo(CGRect bounds, NSDictionary * __nullable pageInfo) NS_AVAILABLE_IOS(3_2);
//返回當前PDF圖形上下文所在頁的尺寸
UIKIT_EXTERN CGRect UIGraphicsGetPDFContextBounds(void) NS_AVAILABLE_IOS(3_2);
//向PDF文檔中的某個區域添加連接
UIKIT_EXTERN void UIGraphicsSetPDFContextURLForRect(NSURL *url, CGRect rect) NS_AVAILABLE_IOS(3_2);
//向PDF文檔中的某個區域添加一個跳轉目標 使其滾動到某點
UIKIT_EXTERN void UIGraphicsAddPDFContextDestinationAtPoint(NSString *name, CGPoint point) NS_AVAILABLE_IOS(3_2);
//向PDF文檔中的某個區域添加一個跳轉目標 使其滾動到某個區域
UIKIT_EXTERN void UIGraphicsSetPDFContextDestinationForRect(NSString *name, CGRect rect) NS_AVAILABLE_IOS(3_2);

上面有提到,在建立PDF圖形上下文時,能夠設置一個信息字典,這個字典中經常使用的能夠進行配置的鍵值以下:

//這個鍵是可選的 對應須要設置爲字符串類型的值 代表文檔做者
kCGPDFContextAuthor
//這個鍵是可選的 對應須要設置爲字符串類型的值 表示生成文檔的命名名稱
kCGPDFContextCreator
//這個鍵是可選的 對應須要設置爲字符串類型的值 表示文檔名稱
kCGPDFContextTitle
//這個鍵設置全部者密碼 須要設置爲CFString的值
kCGPDFContextOwnerPassword
//這個鍵設置用戶密碼 須要設置爲CFString的值
kCGPDFContextUserPassword
//這個鍵設置是否容許在未解鎖狀態下進行打印 須要設置爲CFBollean的值 默認爲容許
kCGPDFContextAllowsPrinting
//這個鍵設置是否容許在未解鎖狀態下進行復制 須要設置爲CFBollean的值 默認爲容許
kCGPDFContextAllowsCopying
//設置輸出規範
kCGPDFContextOutputIntent
kCGPDFContextOutputIntents
//設置文檔的主題 須要設置爲CFString的值
kCGPDFContextSubject
//設置文檔的關鍵字
kCGPDFContextKeywords
//設置密鑰長度
kCGPDFContextEncryptionKeyLength

4、CGContext功能解析

    前邊介紹瞭如何拿到對應的圖形上下文,拿到圖形上下文後,開發者即可以爲所欲爲的經過圖形上下文向目標上繪製內容。CoreGraphics框架中提供的CGContext繪製相關方法解析以下:

//獲取CGContext類在CoreGraphics框架中的id值
CFTypeID CGContextGetTypeID(void);
//將當前圖形上下文進行保存 會執行push入棧
void CGContextSaveGState(CGContextRef cg_nullable c);
//將圖形上下文恢復到保存時的狀態 
void CGContextRestoreGState(CGContextRef cg_nullable c);
//對context內容進行縮放操做
void CGContextScaleCTM(CGContextRef cg_nullable c, CGFloat sx, CGFloat sy);
//對context內容進行平移操做
void CGContextTranslateCTM(CGContextRef cg_nullable c, CGFloat tx, CGFloat ty);
//對context內容進行旋轉操做
void CGContextRotateCTM(CGContextRef cg_nullable c, CGFloat angle);
//對context內容進行transform變換操做
void CGContextConcatCTM(CGContextRef cg_nullable c,CGAffineTransform transform);
//獲取某個context的transform變換對象
CGAffineTransform CGContextGetCTM(CGContextRef cg_nullable c);
//設置繪製的線寬
void CGContextSetLineWidth(CGContextRef cg_nullable c, CGFloat width);
//設置繪製的線帽風格
void CGContextSetLineCap(CGContextRef cg_nullable c, CGLineCap cap);
//設置繪製的線鏈接處風格
void CGContextSetLineJoin(CGContextRef cg_nullable c, CGLineJoin join);
//設置繪製的先轉折處風格
void CGContextSetMiterLimit(CGContextRef cg_nullable c, CGFloat limit);
//設置虛線配置參數
void CGContextSetLineDash(CGContextRef cg_nullable c, CGFloat phase, const CGFloat * __nullable lengths, size_t count);
//設置平滑度
void CGContextSetFlatness(CGContextRef cg_nullable c, CGFloat flatness);
//設置透明度
void CGContextSetAlpha(CGContextRef cg_nullable c, CGFloat alpha);
//設置圖像複合模式
void CGContextSetBlendMode(CGContextRef cg_nullable c, CGBlendMode mode);
//開始新的路徑 舊的路徑將被拋棄
void CGContextBeginPath(CGContextRef cg_nullable c);
//將路徑起點移動到某個點
void CGContextMoveToPoint(CGContextRef cg_nullable c, CGFloat x, CGFloat y);
//向路徑中添加一條線
void CGContextAddLineToPoint(CGContextRef cg_nullable c,CGFloat x, CGFloat y);
//向路徑中添加三次貝塞爾曲線
void CGContextAddCurveToPoint(CGContextRef cg_nullable c, CGFloat cp1x, CGFloat cp1y, CGFloat cp2x, CGFloat cp2y, CGFloat x, CGFloat y);
//向路徑中添加二次貝塞爾曲線
void CGContextAddQuadCurveToPoint(CGContextRef cg_nullable c, CGFloat cpx, CGFloat cpy, CGFloat x, CGFloat y);
//閉合路徑
void CGContextClosePath(CGContextRef cg_nullable c);
//向路徑中添加一個矩形
void CGContextAddRect(CGContextRef cg_nullable c, CGRect rect);
//向路徑中添加一組矩形
void CGContextAddRects(CGContextRef cg_nullable c, const CGRect * __nullable rects, size_t count);
//向路徑中添加一組線條
void CGContextAddLines(CGContextRef cg_nullable c, const CGPoint * __nullable points, size_t count);
//向路徑中添加橢圓
CGContextAddEllipseInRect(CGContextRef cg_nullable c, CGRect rect);
//向路徑中添加圓弧
void CGContextAddArc(CGContextRef cg_nullable c, CGFloat x, CGFloat y, CGFloat radius, CGFloat startAngle, CGFloat endAngle, int clockwise);
void CGContextAddArcToPoint(CGContextRef cg_nullable c, CGFloat x1, CGFloat y1, CGFloat x2, CGFloat y2, CGFloat radius);
//直接向上下文中添加一個路徑對象
void CGContextAddPath(CGContextRef cg_nullable c, CGPathRef cg_nullable path);
//將上下文中的路徑內容替換掉 只留下邊框
void CGContextReplacePathWithStrokedPath(CGContextRef cg_nullable c);
//判斷某個Context的路徑是否爲空
bool CGContextIsPathEmpty(CGContextRef cg_nullable c);
//獲取一個Context路徑當前端點的位置
CGPoint CGContextGetPathCurrentPoint(CGContextRef cg_nullable c);
//獲取路徑的尺寸
CGRect CGContextGetPathBoundingBox(CGContextRef cg_nullable c);
//進行圖形上下文的拷貝
CGPathRef __nullable CGContextCopyPath(CGContextRef cg_nullable c);
//獲取context的路徑中是否包含某個點
bool CGContextPathContainsPoint(CGContextRef cg_nullable c, CGPoint point, CGPathDrawingMode mode);
//進行路徑的繪製
/*
mode枚舉意義以下:
  kCGPathFill,    //進行填充
  kCGPathEOFill,   //補集進行填充繪製
  kCGPathStroke,  //邊框繪製
  kCGPathFillStroke, //邊框繪製並填充
  kCGPathEOFillStroke //補集進行邊框和填充繪製
*/
void CGContextDrawPath(CGContextRef cg_nullable c, CGPathDrawingMode mode);
//進行路徑的填充
void CGContextFillPath(CGContextRef cg_nullable c);
//進行路徑所圍成區域的補集區域填充
void CGContextEOFillPath(CGContextRef cg_nullable c);
//進行邊框繪製
void CGContextStrokePath(CGContextRef cg_nullable c);
//填充某個矩形區域
void CGContextFillRect(CGContextRef cg_nullable c, CGRect rect);
//填充一組矩形區域
void CGContextFillRects(CGContextRef cg_nullable c, const CGRect * __nullable rects, size_t count);
//進行矩形區域的邊框繪製
void CGContextStrokeRect(CGContextRef cg_nullable c, CGRect rect);
//進行矩形區域的邊框繪製 能夠設置邊框寬度
void CGContextStrokeRectWithWidth(CGContextRef cg_nullable c, CGRect rect, CGFloat width);
//清除某個矩形區域
void CGContextClearRect(CGContextRef cg_nullable c, CGRect rect);
//進行虛線區域的填充
void CGContextFillEllipseInRect(CGContextRef cg_nullable c, CGRect rect);
//進行虛線區域邊框的繪製
void CGContextStrokeEllipseInRect(CGContextRef cg_nullable c,CGRect rect);
//繪製一組線
void CGContextStrokeLineSegments(CGContextRef cg_nullable c, const CGPoint * __nullable points, size_t count);
//依據Context當前路徑進行裁剪
void CGContextClip(CGContextRef cg_nullable c);
//進行路徑區域的補集區域裁剪
void CGContextEOClip(CGContextRef cg_nullable c);
//這個方法十分重要 其能夠將圖片裁剪成圖形上下文定義的形狀
void CGContextClipToMask(CGContextRef cg_nullable c, CGRect rect, CGImageRef cg_nullable mask);
//獲取裁剪的區域尺寸
CGRect CGContextGetClipBoundingBox(CGContextRef cg_nullable c);
//進行區域裁剪
void CGContextClipToRect(CGContextRef cg_nullable c, CGRect rect);
//進行一組區域的裁剪
void CGContextClipToRects(CGContextRef cg_nullable c, const CGRect *  rects, size_t count);
//設置圖形上下文的填充顏色
void CGContextSetFillColorWithColor(CGContextRef cg_nullable c, CGColorRef cg_nullable color);
//設置圖形上下文的邊框顏色
void CGContextSetStrokeColorWithColor(CGContextRef cg_nullable c, CGColorRef cg_nullable color);
//設置圖形上下文填充顏色的色彩空間
void CGContextSetFillColorSpace(CGContextRef cg_nullable c,CGColorSpaceRef cg_nullable space);
//設置圖形上下文邊框顏色的色彩空間
void CGContextSetStrokeColorSpace(CGContextRef cg_nullable c, CGColorSpaceRef cg_nullable space);
//下面這些函數與設置顏色和組件模塊屬性相關
void CGContextSetFillColor(CGContextRef cg_nullable c, const CGFloat * cg_nullable components);
void CGContextSetStrokeColor(CGContextRef cg_nullable c, const CGFloat * cg_nullable components);
void CGContextSetFillPattern(CGContextRef cg_nullable c, CGPatternRef cg_nullable pattern, const CGFloat * cg_nullable components);
void CGContextSetStrokePattern(CGContextRef cg_nullable c, CGPatternRef cg_nullable pattern, const CGFloat * cg_nullable components);
void CGContextSetPatternPhase(CGContextRef cg_nullable c, CGSize phase);
void CGContextSetGrayFillColor(CGContextRef cg_nullable c, CGFloat gray, CGFloat alpha);
void CGContextSetGrayStrokeColor(CGContextRef cg_nullable c, CGFloat gray, CGFloat alpha);
void CGContextSetRGBFillColor(CGContextRef cg_nullable c, CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha);
void CGContextSetRGBStrokeColor(CGContextRef cg_nullable c, CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha);
void CGContextSetCMYKFillColor(CGContextRef cg_nullable c, CGFloat cyan, CGFloat magenta, CGFloat yellow, CGFloat black, CGFloat alpha);
void CGContextSetCMYKStrokeColor(CGContextRef cg_nullable c, CGFloat cyan, CGFloat magenta, CGFloat yellow, CGFloat black, CGFloat alpha);
//將當前上下文內容渲染進顏色intent中
void CGContextSetRenderingIntent(CGContextRef cg_nullable c, CGColorRenderingIntent intent);
//在指定區域內渲染圖片
void CGContextDrawImage(CGContextRef cg_nullable c, CGRect rect, CGImageRef cg_nullable image);
//在區域內進行瓦片方式的圖片渲染
void CGContextDrawTiledImage(CGContextRef cg_nullable c, CGRect rect, CGImageRef cg_nullable image);
//獲取上下文渲染的圖像質量
CGInterpolationQuality CGContextGetInterpolationQuality(CGContextRef cg_nullable c);
//設置上下文渲染時的圖像質量
void CGContextSetInterpolationQuality(CGContextRef cg_nullable c, CGInterpolationQuality quality);
//設置進行陰影的渲染
void CGContextSetShadowWithColor(CGContextRef cg_nullable c,  CGSize offset, CGFloat blur, CGColorRef __nullable color);
void CGContextSetShadow(CGContextRef cg_nullable c, CGSize offset, CGFloat blur);
//繪製線性漸變效果
void CGContextDrawLinearGradient(CGContextRef cg_nullable c,  CGGradientRef cg_nullable gradient, CGPoint startPoint, CGPoint endPoint, CGGradientDrawingOptions options);
//繪製半徑漸變效果
void CGContextDrawRadialGradient(CGContextRef cg_nullable c, CGGradientRef cg_nullable gradient, CGPoint startCenter, CGFloat startRadius, CGPoint endCenter, CGFloat endRadius, CGGradientDrawingOptions options);
//用漸變填充上下文的裁剪區域
void CGContextDrawShading(CGContextRef cg_nullable c,  cg_nullable CGShadingRef shading);
//設置繪製的文字間距
void CGContextSetCharacterSpacing(CGContextRef cg_nullable c, CGFloat spacing);
//設置繪製的文字位置
void CGContextSetTextPosition(CGContextRef cg_nullable c, CGFloat x, CGFloat y);
//獲取繪製的文字位置
CGPoint CGContextGetTextPosition(CGContextRef cg_nullable c);
//設置文字transform變換
void CGContextSetTextMatrix(CGContextRef cg_nullable c, CGAffineTransform t);
//獲取文字的transform變換
CGAffineTransform CGContextGetTextMatrix(CGContextRef cg_nullable c);
//設置文字的繪製模式
/*
  kCGTextFill,           //填充
  kCGTextStroke,         //空心 
  kCGTextFillStroke,     //填充加邊框
  kCGTextInvisible,      //在但是區域內
  kCGTextFillClip,       //裁剪填充
  kCGTextStrokeClip,     //裁剪繪製邊框
  kCGTextFillStrokeClip,//進行裁剪
  kCGTextClip
*/
void CGContextSetTextDrawingMode(CGContextRef cg_nullable c, CGTextDrawingMode mode);
//設置繪製文字的字體
void CGContextSetFont(CGContextRef cg_nullable c, CGFontRef cg_nullable font);
//設置繪製文字的字號
void CGContextSetFontSize(CGContextRef cg_nullable c, CGFloat size);
void CGContextShowGlyphsAtPositions(CGContextRef cg_nullable c, const CGGlyph * cg_nullable glyphs, const CGPoint * cg_nullable Lpositions,  size_t count);
//設置繪製的字符風格
void CGContextShowGlyphsAtPositions(CGContextRef cg_nullable c, const CGGlyph * cg_nullable glyphs, const CGPoint * cg_nullable Lpositions, size_t count);
//進行PDF頁的繪製
void CGContextDrawPDFPage(CGContextRef cg_nullable c, CGPDFPageRef cg_nullable page);
//開啓一個新的PDF頁
void CGContextBeginPage(CGContextRef cg_nullable c,  const CGRect * __nullable mediaBox);
//結束當前的PDF頁
void CGContextEndPage(CGContextRef cg_nullable c);
//內存引用加1
CGContextRef cg_nullable CGContextRetain(CGContextRef cg_nullable c);
//內存引用計數減1
void CGContextRelease(CGContextRef cg_nullable c);
//將上下文中的內容當即渲染到目標
void CGContextFlush(CGContextRef cg_nullable c);
//將上下文中的內容進行同步
void CGContextSynchronize(CGContextRef cg_nullable c);
//是否開啓抗鋸齒效果
void CGContextSetShouldAntialias(CGContextRef cg_nullable c,  bool shouldAntialias);
//是否容許抗鋸齒效果
void CGContextSetAllowsAntialiasing(CGContextRef cg_nullable c,  bool allowsAntialiasing);
//是否開啓字體平滑
void CGContextSetShouldSmoothFonts(CGContextRef cg_nullable c, bool shouldSmoothFonts);
//是否容許字體平滑
void CGContextSetAllowsFontSmoothing(CGContextRef cg_nullable c, bool allowsFontSmoothing);
//設置是否開啓subpixel狀態渲染符號
void CGContextSetShouldSubpixelPositionFonts(CGContextRef cg_nullable c, bool shouldSubpixelPositionFonts);
//是否容許subpixel狀態渲染符號
void CGContextSetAllowsFontSubpixelPositioning(CGContextRef cg_nullable c, bool allowsFontSubpixelPositioning);
//這個方法會在當前Context中開啓一個透明的層 以後的繪製會繪製到這個透明的層上
void CGContextBeginTransparencyLayer(CGContextRef cg_nullable c, CFDictionaryRef __nullable auxiliaryInfo);
//在Context中開啓一個透明的層
void CGContextBeginTransparencyLayerWithRect(CGContextRef cg_nullable c, CGRect rect, CFDictionaryRef __nullable auxInfo);
//完成透明層的渲染
void CGContextEndTransparencyLayer(CGContextRef cg_nullable c);
//返回用戶控件的transform變換
CGAffineTransform CGContextGetUserSpaceToDeviceSpaceTransform(CGContextRef cg_nullable c);
//將用戶控件點的座標轉換爲設備控件座標
CGPoint CGContextConvertPointToDeviceSpace(CGContextRef cg_nullable c, CGPoint point);
//將設備空間的點座標轉換爲用戶空間的點座標
CGPoint CGContextConvertPointToUserSpace(CGContextRef cg_nullable c, CGPoint point);
//將用於空間的尺寸轉換爲設備空間的尺寸
CGSize CGContextConvertSizeToDeviceSpace(CGContextRef cg_nullable c, CGSize size);
//將設備空間的尺寸轉換爲用戶空間的尺寸
CGSize CGContextConvertSizeToUserSpace(CGContextRef cg_nullable c, CGSize size);
//將用戶空間的rect轉換爲設備空間的rect
CGRect CGContextConvertRectToDeviceSpace(CGContextRef cg_nullable c, CGRect rect);
//將設備空間的rect轉換爲用戶空間的rect
CGRect CGContextConvertRectToUserSpace(CGContextRef cg_nullable c, CGRect rect);

//下面這些方法已經被棄用 
//設置字體 使用CoreText相關的API代替
void CGContextSelectFont(CGContextRef cg_nullable c, const char * cg_nullable name, CGFloat size, CGTextEncoding textEncoding);
//繪製文本 使用CoreText相關API代替
void CGContextShowText(CGContextRef cg_nullable c, const char * cg_nullable string, size_t length);
//在相應位置繪製文本 使用CoreText相關API代替
void CGContextShowTextAtPoint(CGContextRef cg_nullable c, CGFloat x, CGFloat y, const char * cg_nullable string, size_t length);
//進行符號的繪製 使用CoreText相關API代替
void CGContextShowGlyphs(CGContextRef cg_nullable c, const CGGlyph * __nullable g, size_t count);
//在相應位置繪製符號 使用CoreText相關API代替
void CGContextShowGlyphsAtPoint(CGContextRef cg_nullable c, CGFloat x, CGFloat y, const CGGlyph * __nullable glyphs, size_t count);
//繪製符號 使用一個固定的縮進值 使用CoreText相關API代替
void CGContextShowGlyphsWithAdvances(CGContextRef cg_nullable c, const CGGlyph * __nullable glyphs, const CGSize * __nullable advances, size_t count);
//進行PDF文檔繪製 CGPDFPage相關API代替
void CGContextDrawPDFDocument(CGContextRef cg_nullable c, CGRect rect, CGPDFDocumentRef cg_nullable document, int page);

專一技術,熱愛生活,交流技術,也作朋友。

——琿少 QQ羣:203317592

相關文章
相關標籤/搜索