Quartz2d

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 painter’s model

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帮我们完成。

Quartz drawing destinations

绘制目标包括以下几种:

  • 位图
  • 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 的坐标系统

The Quartz coordinate system

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).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值