1. 向量绘制,用路径来描述图形,可以是闭合也可以不是闭合。
2. Building Blocks:
- 点: CGContextMoveToPoint
-线: CGContextAddLineToPoint, CGContextAddLines
-圆弧:CGContextAddArc,CGContextAddArcToPoint
-曲线:Quadratic/Cubic Bezier曲线, CGContextAddCurveToPoint, CGContextAddQuadCurveToPoint
- CGContextClosePath会被某些操作默认执行。
- 椭圆:CGContextAddEllipseInRect;
- 矩形: CGContextAddRect;
3. 创建Path CGContextBeginPath + CGContextMoveToPoint
4. Painting Path != Create Path
5. Mutable Path: Path对象,独立于Context存在。CGContextAddPath来使用它。
- CGPathCreateMutable = CGContextBeginPath
- CGPathMoveToPoint = CGContextMoveToPoint
- CGPathAddLineToPoint = CGContextAddLineToPoint
- CGPathAddCurveToPoint = CGContextAddCurveToPoint
- CGPathAddEllipseInRect = CGContextAddEllipseInRect
- CGPathAddArc = CGContextAddArc
- CGPathAddRect = CGContextAddRect
- CGPathCloseSubPath = CGContextCloseSubPath
6. 描边
- 线宽:
- 连接方式:Miter尖角,Round圆角,Bevel平角
- 线头:Butt平头,Round圆头,Projecting扩展平头
- 角限:限制尖角连接的范围
- 点划模板:
- 颜色空间:
- 颜色:
- StrokePattern?
CGContextStrokePath/CGContextStrokeRect/CGContextStrokeRectWithWidth/CGContextStrokeEllipseInRect/CGContextStrokeLineSegment/CGContextDrawPath
7.填充规则:
- nonzero winding:CGContextFillPath从某点出发向图形边缘做一条射线,如果射线和图形某条边相交,且该边从坐向右穿过射线,则相交计数+1,如果该边从右向左穿过射线,则相交计数-1。如果最后相交计数为1,则该点在图形内。
- even odd:CGContextEOFillPath从某点出发向图形边缘做一条射线,如果射线和图形边相交点数为奇数,则该点在图形内。
8. CGContextFillPath/CGContextEOFillPath/CGContextFillRect/CGContextFillRects/CGContextFillEllipseInRect/CGContextDrawPath
9. 混合:CGContextSetBlendMode - GraphicsState, 通常:
- Normal: result = result = (alpha*fore) + (1.0-alpha)*back;
- Multiply: result = fore*back;
- Screen: result = 1.0-(1.0-fore)*(1.0-back);
- Overlay: result = gray(back)>0.5?(1.0-2.0*(1.0-back)*(1.0-fore):fore*back*2.0f;
- Darken: result = min(fore,back);
- Lighten: result = max(fore,back);
- Color Dodge: result = back/(1.0-fore);
- Color Burn: result = 1.0 - (1.0-back)/fore;
- Soft Light: result = gray(fore)>0.5? 1.0 - (1.0-back)*(1.5 - fore):back*(fore+0.5);
- Hard Light: result = gray(fore)>0.5?1.0 - 2.0*(1.0-back)*(1.0-fore):2.0*back*fore;
- Difference: result = abs(fore-back);
- Exclusion: result = 0.5 - 2.0*(fore - 0.5)*(back-0.5);
- Hue: result = lum(back), sat(back),hue(fore);
- Saturtation: result = lum(back),sat(fore),hue(back);
- Color: result = lum(back),sat(fore),hue(fore);
- Luminosity: result = lum(fore),sat(back),hue(back);
10.裁剪: CGConextClip/CGContextEOClip/CGContextClipToRect/CGContextClipToRects/CGContextClipToMask;