Quartz2D教程
page
Graphic Context
-
数据类型
- CGPathRef
- CGImageRef
- CGLayerRef
- CGPatternRef
- CGFunctionRef
- CGColorRef,CGColorSpaceRef
- CGImageSourceRef CGImageDestinationRef (destination [,desti'neiʃən] Embedded Image n. 目的地,终点)
- CGFontRef
- CGPDFDictionaryRef CGPDFObjectRef CGPDFPageRef CGPDFstream CGPDFStringRef CGPDFArrayRef
*CGPDFScannerRef CGPDFContentStreamRef
*CGPSConverterRef
//获取图形上下文 指的是当前view 的frame
CGContextRef context = UIGraphicsGetCurrentContext();
//填充颜色
CGContextSetRGBFillColor(context, 1, 0, 0, 1);
//填充矩形区域
CGContextFillRect(context, CGRectMake (0, 0, 200, 100));
//填充颜色
CGContextSetRGBFillColor(context, 0, 0, 1, .5);
//填充矩形区域
CGContextFillRect(context, CGRectMake (0, 0, 100, 200));
`` `
//使用 UIGraphicsBeginImageContextWithOptions 返回的绘图上下文与UIKit 的坐标系统相同。
UIGraphicsBeginImageContext([UIScreen mainScreen].bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 1, 0, 0, 1);
CGContextFillRect(context, CGRectMake (0, 0, 200, 100));
CGContextSetRGBFillColor(context, 0, 0, 1, .5);
CGContextFillRect(context, CGRectMake (0, 0, 100, 200));
//当前上下文作为图片返回
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();//CGBitmapContextCreateImage(context)
//结束图片上下文
UIGraphicsEndImageContext();