Rambo丶Q

导航

CGContext 解释

Managing Graphics Contexts:管理图形上下文

  1. CGContextFlush // 强制立即渲染未执行在一个窗口上下文上的绘图操作到目标设备。系统会在合适的时机自动调用此函数,手动调用可能会在表现上引起相反的作用,所以一般条件下,你不需要调用此函数。 CGContextGetTypeID//返回Quartz图形上下文的类型标识符。
  2. CGContextRelease // CG不支持ARC需要手动释放,相对应的还有CGColorRelease,CGColorSpaceRelease,CGDataConsumerRelease,CGDataProviderRelease,CGFontRelease等CG的所有对象
  3. CGContextRetain//与CGRetain类似,但是当c是NULL的时候不会引起一个运行时崩溃
  4. CGContextSynchronize//正常条件下,无需手动调用

Saving and Restoring the Current Graphics State:保存和恢复当前图形上下文的状态

//因为图形上下文在每一时刻都有一个确定的状态,该状态概括了图形上下文所有属性的设置。为了便于操作这些状态,图形上下文提供了一个用来持有状态的栈。

  1. CGContextSaveGState //上下文会将完整的当前状态压入栈顶;支持这些属性压入栈顶保存。CTM (current transformation matrix);clip region;image interpolation quality;line width;line join;miter limit;line cap;line dash;flatness;should anti-alias;rendering intent;fill color space;stroke color space;fill color;stroke color;alpha value;font;font size;character spacing;text drawing mode;shadow parameters;the pattern phase;the font smoothing parameter;blend mode
  2. CGContextRestoreGState //上下文查找处在栈顶的状态,并设置当前上下文状态为栈顶状态。

Getting and Setting Graphics State Parameters:图形上下文状态参数

  1. CGContextSetLineWidth//设置线宽
  2. CGContextSetLineCap//设置线帽样式,默认kCGLineCapButt平角,kCGLineCapRound延长以一半宽为半径的半圆,kCGLineCapSquare延长一一半宽为长的矩形
  3. CGContextSetLineJoin//折角链接点样式,默认kCGLineJoinMiter直角转折,kCGLineJoinRound圆角转折,kCGLineJoinBevel比round搓的延长半个宽的转折
  4. CGContextSetMiterLimit//设置图像上下文中的连接线的斜接限制.如果当前交叉线绘图模式是kCGLineJoinMiter( CGContextSetLineJoin),quartz根据设置的miter值来判断线的join是bevel或者miter。具体的模式是:将miter的长度除以线的宽度,如果小于设置的mitetLimit值,则join style为bevel;我也不知道这个miter值是多少。
  5. CGContextSetLineDash//设置线分割点
  6. CGContextGetInterpolationQuality//影响图片质量的http://stackoverflow.com/questions/5685884/imagequality-with-cgcontextsetinterpolationquality
  7. CGContextSetInterpolationQuality
  8. CGContextSetPatternPhase//查看demo的MyView17中的调用。FillPattern平铺效果并不与箭头的三角形内部相符合:最底部的似乎只平铺了一半蓝色。这是因为一个模板的定位并不关心你填充(描边)的形状,总的来说它只关心图形上下文。我们可以调用CGContextSetPatternPhase函数改变模板的定位。
  9. CGContextSetFillPattern//在指定的图形上下文设置的填充图案模式。查看demo的MyView17中的调用.
  10. CGContextSetRenderingIntent//在当前图形状态设置渲染意向。几个枚举值都设置了下,看不出啥效果变化
  11. CGContextSetStrokePattern//在指定的图形上下文设置描边图案。stroke同fill,见MyView17
  12. CGContextSetBlendMode//决定你当前绘制的图形与已经存在的图形如何被合成
  13. CGContextSetFlatness//控制如何准确的绘制曲线,设置falatness的值小于1.0,曲线绘制会更平滑,但是绘制时间会加长。大多数情况,我们不需要改变flatness的值。http://blog.csdn.net/zy780529/article/details/7341341
  14. CGContextSetShouldAntialias//设置图形上下文的抗锯齿开启或关闭。window和bitmap context位图上下文默认打开。其他的上下文类型是关闭的。is a graphics state parameter.
  15. CGContextSetAllowsAntialiasing//是否允许反锯齿。Quartz在一个图形上下文中实现抗锯齿CGContextSetAllowsAntialiasing和CGContextSetShouldAntialias都是ture才行。is not a graphics state parameter.
  16. CGContextSetShouldSmoothFonts//This parameter is part of the graphics state. Because of this, you use this when you want to temporarily override this setting in a drawing method.
  17. CGContextSetAllowsFontSmoothing//is not a graphics state parameter.
  18. CGContextSetShouldSubpixelPositionFonts//亚像素,开启允许,字体绘制的边界可以触及非整数边界,不开启则是整数边界
  19. CGContextSetAllowsFontSubpixelPositioning//
  20. CGContextSetShouldSubpixelQuantizeFonts//需要开启这个Subpixel Font才能生效
  21. CGContextSetAllowsFontSubpixelQuantization//

Constructing Paths:构造路径

  1. CGContextAddArc//绘制圆弧
  2. CGContextAddArcToPoint//这个不是很好理解,具体是根据两条圆弧切线来绘制圆弧见MyView21
  3. CGContextAddCurveToPoint//贝塞尔曲线。根据四个点绘制圆弧。当前点,控制点1,控制点2,终点
  4. CGContextAddLines//绘制多条线
  5. CGContextAddLineToPoint//绘制一条线
  6. CGContextAddPath//通常,一系列点组合一起构成一个形状,而若干个形状组合在一起可以构造一个路径,路径可以规则也可以不规则,随意组合。http://blog.csdn.net/cocoarannie/article/details/10015345
  7. CGContextCopyPath
  8. CGContextAddQuadCurveToPoint//二次曲线。三点绘制,当前点,控制点,终点。http://www.oschina.net/question/262659_142988
  9. CGContextAddRect//
  10. CGContextAddRects//
  11. CGContextBeginPath//一个图形上下文只能有一条path,调用此方法,就会抛弃之前包含的current path。
  12. CGContextClosePath
  13. CGContextMoveToPoint//新的子路径的起始点
  14. CGContextAddEllipseInRect//画椭圆。

Painting Paths:绘制路径

  1. CGContextClearRect//绘制透明的矩形。只在window和bitmap上下文中生效。其他的取决于设备。所以不应该在window和bitmap之外使用。
  2. CGContextDrawPath//kCGPathFill, kCGPathEOFill, kCGPathStroke, kCGPathFillStroke, or kCGPathEOFillStroke.//填充一个路径的时候,路径里面的子路径都是独立填充的。//假如是重叠的路径,决定一个点是否被填充,有两种规则//1,nonzero winding number rule:非零绕数规则,假如一个点被从左到右跨过,计数器+1,从右到左跨过,计数器-1,最后,如果结果是0,那么不填充,如果是非零,那么填充。//2,even-odd rule: 奇偶规则,假如一个点被跨过,那么+1,最后是奇数,那么要被填充,偶数则不填充,和方向没有关系。//http://blog.csdn.net/freshforiphone/article/details/8273023
  3. CGContextEOFillPath//奇偶规则填充路径
  4. CGContextFillPath
  5. CGContextFillRect
  6. CGContextFillRects
  7. CGContextFillEllipseInRect
  8. CGContextStrokePath
  9. CGContextStrokeRect
  10. CGContextStrokeRectWithWidth
  11. CGContextStrokeEllipseInRect
  12. CGContextStrokeLineSegments

Gettign Infomation About Paths:获取路径信息

  1. CGContextIsPathEmpty//判断当前上下文是否包含子路径
  2. CGContextGetPathCurrentPoint//不存在path就返回CGPointZero
  3. CGContextGetPathBoundingBox//最小包含path的矩形。包括贝兹曲线和二次曲线的控制点
  4. CGContextPathContainsPoint//检查point是否在当前path里面

Modifying Cliping Paths:修改裁剪路径

  1. CGContextClip//修改当前剪贴路径,使用非零绕数规则。
  2. CGContextEOClip//修改当前剪贴路径,使用奇偶规则。
  3. CGContextClipToRect//裁剪矩形
  4. CGContextClipToRects//
  5. CGContextGetClipBoundingBox//返回保护裁剪区域的最小矩形,包括控制点
  6. CGContextClipToMask//

Setting Color, Color Space, and Shadow Values:设置颜色,色彩空间和阴影值

  1. CGContextSetAlpha
  2. CGContextSetCMYKFillColor//cyan,magenta,yellow,black
  3. CGContextSetFillColor//苹果强烈建议使用CGContextSetFillColorWithColor http://stackoverflow.com/questions/25486594/why-is-cgcontextsetfillcolorwithcolor-preferred-over-cgcontextsetfillcolor
  4. CGContextSetCMYKStrokeColor
  5. CGContextSetFillColorSpace//通过常量CGColorSpaceRef来设置颜色
  6. CGContextSetFillColorWithColor
  7. CGContextSetGrayFillColor
  8. CGContextSetGrayStrokeColor
  9. CGContextSetRGBFillColor
  10. CGContextSetRGBStrokeColor
  11. CGContextSetShadow
  12. CGContextSetShadowWithColor
  13. CGContextSetStrokeColor//建议使用CGContextSetStrokeColorWithColor
  14. CGContextSetStrokeColorSpace//通过常量CGColorSpaceRef来设置颜色
  15. CGContextSetStrokeColorWithColor

Transforming User Space:转换用户空间

  1. CGContextConcatCTM//使用 transform 变换矩阵对 CGContextRef 的坐标系统执行变换,通过使用坐标矩阵可以对坐标系统执行任意变换
  2. CGContextGetCTM//获取CGContextRef的坐标系统的变换矩阵
  3. CGContextRotateCTM//旋转
  4. CGContextScaleCTM//放大
  5. CGContextTranslateCTM//移动

Using Transparency Layers:使用透明图层

  1. CGContextBeginTransparencyLayer//透明层(TransparencyLayers)通过组合两个或多个对象来生成一个组合图形。组合图形被看成是单一对象。当需要在一组对象上使用特效时,透明层非常有用 http://southpeak.github.io/blog/2014/12/10/quartz-2dbian-cheng-zhi-nan-zhi-jiu-:tou-ming-ceng/
  2. CGContextBeginTransparencyLayerWithRect//
  3. CGContextEndTransparencyLayer//

Drawing an Image to a Graphics Context:绘制图像图形上下文

  1. CGContextDrawImage
  2. CGContextDrawTiledImage//平铺的方式,见MyView28

Drawing PDF Content to a Graphics Context:绘制一个图形上下文的PDF内容

  1. CGContextDrawPDFPage//绘制一个PDF页面到当前的用户空间

Drawing With a Gradient:制图渐变

  1. CGContextDrawLinearGradient//绘制一个渐变填充定义的出发点和落脚点沿线变化。轴向渐变(也称为线性渐变)沿着由两个端点连接的轴线渐变。 MyView29
  2. CGContextDrawRadialGradient//绘制一个沿着由所提供的开始和结束的圆限定的区域变化的渐变填充。径向渐变也是沿着两个端点连接的轴线渐变,不过路径通常由两个圆来定义。 MyView29

Drawing With a Shading:制图底纹

  1. CGContextDrawShading//使用指定的阴影的背景,填充剪切路径。

Setting Up a Page-Based Graphics Context:建立一个基于页面的图形上下文

  1. CGContextBeginPage//基于页面的图形上下文中开始了新的一页。
  2. CGContextEndPage//在基于页面的图形上下文结束当前的页面。

Drawing Glyphs:绘制字形 use the CoreText API instead

  1. CGContextShowGlyphs//在当前文本位置显示一个数组的字形。
  2. CGContextShowGlyphsAtPoint//在指定的位置显示一个数组的字形。
  3. CGContextShowGlyphsWithAdvances//绘制具有不同的偏移量的一个数组字形。
  4. CGContextShowGlyphsAtPositions//在所提供的位置绘制字形。

Drawing Text:绘制文本

  1. CGContextGetTextMatrix//返回当前文本矩阵。return CGAffineTransform
  2. CGContextGetTextPosition//返回在绘制文本的位置。
  3. CGContextSelectFont//设置在一个图形上下文的字体和字体大小。Use Core Text instead.
  4. CGContextSetCharacterSpacing//设置当前字符间距。
  5. CGContextSetFont//设置上下文的字体。
  6. CGContextSetFontSize//设置上下文的字体大小。
  7. CGContextSetTextDrawingMode//设置当前文本的绘图模式。
  8. CGContextSetTextMatrix//设置当前文本矩阵。
  9. CGContextSetTextPosition//设置要绘制文本的位置。
  10. CGContextShowText//在当前文本位置,由目前的文本矩阵指定的点显示一个字符数组。Use Core Text instead.
  11. CGContextShowTextAtPoint//在指定的位置显示一个字符串。Use Core Text instead.

Converting Between Device Space and User Space:设备空间和用户空间之间的转换

  1. CGContextGetUserSpaceToDeviceSpaceTransform
  2. CGContextConvertPointToDeviceSpace
  3. CGContextConvertPointToUserSpace
  4. CGContextConvertSizeToDeviceSpace
  5. CGContextConvertSizeToUserSpace
  6. CGContextConvertRectToDeviceSpace
  7. CGContextConvertRectToUserSpace

 

CGContextDrawPDFDocument//use the CGPDFPage API instead

Demo见:

  1. https://github.com/RamboQiu/QJYQuartzDemo.git 自己写的简单例子
  2. https://developer.apple.com/library/ios/samplecode/QuartzDemo/QuartzDemo.zip 官方例子

参考文献:

  1. http://www.cocoachina.com/industry/20140115/7703.html
  2. http://my.oschina.net/ospost90s/blog/509396
  3. http://southpeak.github.io/blog/archives/

posted on 2016-06-28 17:49  Rambo丶Q  阅读(769)  评论(0编辑  收藏  举报