您的位置:首页 > 其它

Quartz2d

2015-06-09 11:25 288 查看

Core Graphics 之 Quartz2D

Quartz2D概述

Quartz 2D is a two-dimensional drawing engine accessible in the iOS environment and from all Mac OS X application environments outside of the kernel.

页面

Quartz 2D uses the painter’s model for its imaging. In the painter’s model, each successive drawing operation applies a layer of “paint” to an output “canvas,” often called a page. The paint on the page can be modified by overlaying more paint through additional drawing operations. An object drawn on the page cannot be modified except by overlaying more paint. This model allows you to construct extremely sophisticated images from a small number of powerful primitives.



The page may be a real sheet of paper (if the output device is a printer); it may be a virtual sheet of paper (if the output device is a PDF file); it may even be a bitmap image. The exact nature of the page depends on the particular graphics context you use.

绘图目标

绘图目标,是一个不透明的数据类型CGContextRef,它封装了Quartz用来绘制图片到输出设备(PDF,位图或窗口)的信息。这些信息包括在一个页面上绘图的绘图参数和具体的设备相关的呈现特性(representation)。

你可以仅仅提供不同的绘图目标(Graphics Context)就可以将同一张图片绘制在不同的设备上,而不需要进行任何设备相关的计算,这些都由Quartz帮我们完成。



绘制目标包括以下几种:

位图

PDF

窗口

图层

打印机

一些不透明的数据类型

The Quartz 2D API defines a variety of opaque data types in addition to graphics contexts. Because the API is part of the Core Graphics framework, the data types and the routines that operate on them use the CG prefix.

CGPathRef 用于矢量图中,创建填充和勾勒的路径

CGImageRef 用于表示位图和位图遮罩(mask)

CGLayerRef 用来表示绘图图层

CGPatternRef 用在重复的绘制中

CGShadingRef和CGGradientRef 用在绘制渐变

CGFunctionRef 用来定义回调函数,其可以接受任意个数的浮点参数

CGColorRef和CGColorSpaceRef Quartz中对颜色的诠释

CGImageSourceRef和CGImageDestinationRef 在Quartz中,用它们将数据移入或者移出

CGFontRef 用来绘制文本

CGPDFDictionaryRef, CGPDFObjectRef, CGPDFPageRef, CGPDFStream, CGPDFStringRef, and CGPDFArrayRef 用来访问PDF的元数据

CGPDFScannerRef和CGPDFContentStreamRef 用来解析PDF元数据

绘图状态 (Graphics States)

Quartz modifies the results of drawing operations according to the parameters in the current graphics state. The graphics state contains parameters that would otherwise be taken as arguments to drawing routines. Routines that draw to a graphics context consult the graphics state to determine how to render their results. For example, when you call a function to set the fill color, you are modifying a value stored in the current graphics state. Other commonly used elements of the current graphics state include the line width, the current position, and the text font size.

The graphics context contains a stack of graphics states. When Quartz creates a graphics context, the stack is empty. When you save the graphics state, Quartz pushes a copy of the current graphics state onto the stack. When you restore the graphics state, Quartz pops the graphics state off the top of the stack. The popped state becomes the current graphics state.

To save the current graphics state, use the function CGContextSaveGState to push a copy of the current graphics state onto the stack. To restore a previously saved graphics state, use the function CGContextRestoreGState to replace the current graphics state with the graphics state that’s on top of the stack.

Quartz 2D 的坐标系统



Quartz accomplishes device independence with a separate coordinate system(用户空间)mapping it to the coordinate system of the output device(设备空间)using the current transformation matrix, or CTM.The current transformation matrix is a particular type of matrix called an affine transform, which maps points from one coordinate space to another by applying translation, rotation, and scaling operations (calculations that move, rotate, and resize a coordinate system).
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  quartz