美文网首页
Quartz 2D 编程指南一:Quartz 2D预览

Quartz 2D 编程指南一:Quartz 2D预览

作者: bobociel | 来源:发表于2017-05-27 15:58 被阅读224次
    logo.png

    Overview of Quartz 2D

    Quartz 2D is two-dimensional drawing engine accessible in the iOS environment and from all Mac OS X application environments outside of the kernel. You can use the Quartz 2D application programming interface(API) to gain access to features such as path-based drawing, painting with transparency, shading, drawing shadows, transparency layers, color management, anti-aliased rendering, PDF document generation, and PDF metadata access. Whenever possible, Quartz 2D leverages the power of the graphics hardware.

    Quartz 2D是一个二维图形绘制引擎,可在iOS环境中和内核之外的所有Mac OS X应用程序环境中访问。您可以使用Quartz 2D应用程序编程接口(API)访问基于路径的绘图,绘制透明度,着色,绘制阴影,透明层,颜色管理,反锯齿渲染,PDF文档生成和PDF等功能元数据访问。这就是Quartz 2D利用图形硬件的力量。

    In Mac OS X,Quartz 2D can work with all other graphic and imaging technologies-Core Image, Core Video, OpenGL, and QuickTime. It's possible to create an image in Quartz from a QuickTime graphics importer, using the QuickTime function GraphicsImportCreateCGImage. See QuickTime Framework Reference for details. Moving Data Between Quartz 2D and Core Image in Mac OS X describes how you can provide images to Core Image, which is a framework that supports image processing.

    Similarly, in iOS,Quartz 2D works with all available graphics and animation technologies, such as Core Animation, OpenGL ES, and the UIKit class.

    在Mac OS X中,Quartz 2D可以与其它图形图像技术混合使用 - Core Image,Core Video,OpenGL和QuickTime。可以使用QuickTime函数GraphicsImportCreateCGImage从QuickTime图形导入器在Quartz中创建图像。有关详细信息,请参阅QuickTime Framework Reference。在Mac OS X中在Quartz 2D和Core Image之间移动数据描述了如何向Core Image提供图像,Core Image是一个支持图像处理的框架。
    类似地,在iOS中,Quartz 2D可以与其它可用的图形动画技术混合使用,例如Core Animation,OpenGL ES和UIKit类。

    The Page

    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.

    Quartz 2D在图像中使用了绘画者模型(painter’s model)。在绘画者模型中,每个连续的绘制操作都是将一个绘制层(a layer of ‘paint’)放置于一个画布(‘canvas’),我们通常称这个画布为(Page)。 Page上的绘图可以通过额外的绘制操作来叠加更多的绘图。Page上的图形对象只能通过叠加更多的绘图来改变。这个模型允许我们使用小的图元来构建复杂的图形。

    Figure 1-1 shows how the painter’s model works. To get the image in the top part of the figure, the shape on the left was drawn first followed by the solid shape. The solid shape overlays the first shape, obscuring all but the perimeter of the first shape. The shapes are drawn in the opposite order in the bottom of the figure, with the solid shape drawn first. As you can see, in the painter’s model the drawing order is important.

    图1-1展示了绘画者模型如何工作。从图中可以看出不同的绘制顺序所产生的效果不一样。


    Figure 1-1

    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.
    该页面可能是真实的纸张(如果输出设备是打印机); 它可能是虚拟的纸张(如果输出设备是PDF文件); 它甚至可能是一个位图图像。 页面的确切属性取决于您使用的特定图形上下文。

    Drawing Destinations:The Graphic Context

    A graphics context is an opaque data type CGContextRef that encapsulates the information Quartz uses to draw images to an output device, such as a PDF file, a bitmap, or a window on a display. The information inside a graphics context includes graphics drawing parameters and a device-specific representation of the paint on the page. All objects in Quartz are drawn to, or contained by, a graphics context.

    图形上下文是一种不透明数据类型(CGContextRef),用于封装Quartz将图像绘制到输出设备(如PDF文件,位图或窗口)上的信息。 图形上下文中的信息包括图形绘图参数和设备相关的表示形式。 Quartz中的所有对象都被绘制到或被包含在图形上下文。

    You can think of a graphics context as a drawing destination, as shown in Figure 1-2. When you draw with Quartz, all device-specific characteristics are contained within the specific type of graphics context you use. In other words, you can draw the same image to a different device simply by providing a different graphics context to the same sequence of Quartz drawing routines. You do not need to perform any device-specific calculations; Quartz does it for you.

    我们可以将Graphics Context想像成绘制目标,如图1-2所示。当用Quartz绘图时,所有设备相关的特性都包含在我们所使用的Graphics Context中。换句话说,我们可以简单地给Quartz绘图序列指定不同的Graphics Context,就可将相同的图像绘制到不同的设备上。我们不需要任何设备相关的计算;这些都由Quartz替我们完成。

    Figure 1-2

    These graphics contexts are available to your application:

    • A bitmap graphics context allows you to paint RGB colors, CMYK colors, or grayscale into a bitmap. A bitmap is a rectangular array (or raster) of pixels, each pixel representing a point in an image. Bitmap images are also called sampled images.
    • A PDF graphics context allows you to create a PDF file. In a PDF file, your drawing is preserved as a sequence of commands. There are some significant differences between PDF files and bitmaps:
    • PDF files, unlike bitmaps, may contain more than one page.
    • When you draw a page from a PDF file on a different device, the resulting image is optimized for the display characteristics of that device.
    • PDF files are resolution independent by nature—the size at which they are drawn can be increased or decreased infinitely without sacrificing image detail. The user-perceived quality of a bitmap image is tied to the resolution at which the bitmap is intended to be viewed.
      See Creating a PDF Graphics Context.
    • A window graphics context is a graphics context that you can use to draw into a window. Note that because Quartz 2D is a graphics engine and not a window management system, you use one of the application frameworks to obtain a graphics context for a window. See Creating a Window Graphics Context in Mac OS X for details.
    • A layer context (CGLayerRef) is an offscreen drawing destination associated with another graphics context. It is designed for optimal performance when drawing the layer to the graphics context that created it. A layer context can be a much better choice for offscreen drawing than a bitmap graphics context. See Core Graphics Layer Drawing.
    • When you want to print in Mac OS X, you send your content to a PostScript graphics context that is managed by the printing framework. See Obtaining a Graphics Context for Printing for more information.

    Quartz提供了以下几种类型的Graphics Context,详细的介绍将在后续章节说明。

    • 位图图形上下文允许您将RGB颜色,CMYK颜色或灰度绘制到位图中。 位图是像素的矩形阵列(或栅格),每个像素表示图像中的点。 位图图像也称为采样图像。
    • PDF图形上下文允许您创建一个PDF文件。 在PDF文件中,您的绘图将作为一系列命令保留。 PDF文件和位图之间有一些显着的区别:
    • PDF文件与位图不同,可能包含多个页面。
    • 当您在不同设备上的PDF文件中绘制页面时,生成的图像应根据该设备的显示特性进行优化。
    • PDF文件是本质上独立的分辨率 - 它们绘制的大小可以无限增加或减少,而不会牺牲图像细节。位图图像的用户感知质量与打算观看位图的分辨率相关。
      请参阅Creating a PDF Graphics Context
    • window graphics context 是一个图形上下文,您可以使用它来绘制窗口。注意,因为Quartz 2D是一个图形引擎而不是一个窗口管理系统,你使用一个应用程序框架来获取一个窗口的图形上下文。有关详细信息,请参阅Creating a Window Graphics Context in Mac OS X
    • layer context (CGLayerRef)是与另一图形上下文相关联的离屏绘制目的地。它被设计为在将图层绘制到创建它的图形上下文时获得最佳性能。对于屏幕外绘制,层上下文可以是比位图图形上下文更好的选择。请参阅Core Graphics Layer Drawing.
    • 当您要在Mac OS X中打印时,您将内容发送到由打印框架管理的PostScript图形上下文。有关详细信息,请参阅Obtaining a Graphics Context for Printing

    Quartz 2D Opaque Data Types

    不透明数据类型

    The type FILE, declared in <stdio.h>. You don't know what constitutes the type; 
    you only use pointers to the type and the library itself knows the internals of the type and can use the data.
    类型FILE,在<stdio.h>中声明。你不知道是什么构成的类型;您只使用指向该类型的指针,而且库本身知道该类型的内部并可以使用该数据。
    

    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.
    Quartz 2D creates objects from opaque data types that your application operates on to achieve a particular drawing output. Figure 1-3 shows the sorts of results you can achieve when you apply drawing operations to three of the objects provided by Quartz 2D. For example:

    • You can rotate and display a PDF page by creating a PDF page object, applying a rotation operation to the graphics context, and asking Quartz 2D to draw the page to a graphics context.
    • You can draw a pattern by creating a pattern object, defining the shape that makes up the pattern, and setting up Quartz 2D to use the pattern as paint when it draws to a graphics context.
    • You can fill an area with an axial or radial shading by creating a shading object, providing a function that determines the color at each point in the shading, and then asking Quartz 2D to use the shading as a fill color.

    Figure 1-3 Opaque data types are the basis of drawing primitives in Quartz 2D


    图1-3例举了三个使用Quartz 2D的绘制操作所获得的图像

    除了 Graphics Context 之外,Quartz 2D API还定义一些数据类型。由于这些API就Core Graphics框架的一部分,所以这些数据类型都是以CG开头的。
    Quartz 2D使用这些数据类型来创建对象,通过操作这些对象来获取特定的图形。图1-3例举了三个使用Quartz 2D的绘制操作所获得的图像。例如:

    • 你可以创建PDF页面
    • 你可以路径对象
    • 你可以创建渐变

    The opaque data types available in Quartz 2D include the following:

    • CGPathRef, used for vector graphics to create paths that you fill or stroke. See Paths.
    • CGImageRef, used to represent bitmap images and bitmap image masks based on sample data that you supply. See Bitmap Images and Image Masks.
    • CGLayerRef, used to represent a drawing layer that can be used for repeated drawing (such as for backgrounds or patterns) and for offscreen drawing. See Core Graphics Layer Drawing
    • CGPatternRef, used for repeated drawing. See Patterns.
    • CGShadingRef and CGGradientRef, used to paint gradients. See Gradients.
    • CGFunctionRef, used to define callback functions that take an arbitrary number of floating-point arguments. You use this data type when you create gradients for a shading. See Gradients.
    • CGColorRef and CGColorSpaceRef, used to inform Quartz how to interpret color. See Color and Color Spaces.
    • CGImageSourceRef and CGImageDestinationRef
      , which you use to move data into and out of Quartz. See Data Management in Quartz 2D and Image I/O Programming Guide.
    • CGFontRef, used to draw text. See Text.
    • CGPDFDictionaryRef, CGPDFObjectRef, CGPDFPageRef, CGPDFStream
      , CGPDFStringRef, and CGPDFArrayRef, which provide access to PDF metadata. See PDF Document Creation, Viewing, and Transforming.
    • CGPDFScannerRef and CGPDFContentStreamRef, which parse PDF metadata. See PDF Document Parsing.
    • CGPSConverterRef, used to convert PostScript to PDF. It is not available in iOS. See PostScript Conversion.

    Quartz 2D包含一下类型:

    • CGPathRef:用于向量图,可创建路径,并进行填充或描画(stroke)
    • CGImageRef:用于表示bitmap图像和基于采样数据的bitmap图像遮罩。
    • CGLayerRef:用于表示可用于重复绘制(如背景)和幕后(offscreen)绘制的绘画层
    • CGPatternRef:用于重绘图
    • CGShadingRef、CGGradientRef:用于绘制渐变
    • CGFunctionRef:用于定义回调函数,该函数包含一个随机的浮点值参数。当为阴影创建渐变时使用该类型
    • CGColorRef, CGColorSpaceRef:用于告诉Quartz如何解释颜色
    • CGImageSourceRef,CGImageDestinationRef:用于在Quartz中移入移出数据
    • CGFontRef:用于绘制文本
    • CGPDFDictionaryRef, CGPDFObjectRef, CGPDFPageRef, CGPDFStream, CGPDFStringRef, and CGPDFArrayRef:用于访问PDF的元数据
    • CGPDFScannerRef, CGPDFContentStreamRef:用于解析PDF元数据
    • CGPSConverterRef:用于将PostScript转化成PDF。在iOS中不能使用。

    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.

    Quartz通过修改当前图形状态(current graphics state)来修改绘制操作的结果。图形状态包含用于绘制程序的参数。绘制程序根据这些绘图状态来决定如何渲染结果。例如,当你调用设置填充颜色的函数时,你将改变存储在当前绘图状态中的颜色值。当前图形状态的其他常用元素包括行宽、位置和文本字体大小。

    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.

    Graphics Context包含一个绘图状态栈。当Quartz创建一个Graphics Context时,栈为空。当保存图形状态时,Quartz将当前图形状态的一个副本压入栈中。当还原图形状态时,Quartz将栈顶的图形状态出栈。出栈的状态成为当前图形状态。

    可使用函数CGContextSaveGState来保存图形状态,CGContextRestoreGState来还原图形状态。

    Note that not all aspects of the current drawing environment are elements of the graphics state. For example, the current path is not considered part of the graphics state and is therefore not saved when you call the function CGContextSaveGState. The graphics state parameters that are saved when you call this function are listed in Table 1-1.

    注意:并不是当前绘制环境的所有方面都是图形状态的元素。如,图形状态不包含当前路径(current path)。下面列出了图形状态相关的参数:

    Parameters Discussed in this chapter 翻译
    Current transformation matrix (CTM) Transform 当前转换矩阵
    Clipping area Paths 裁剪区域
    Line Paths 线
    Accuracy of curve estimation (flatness) Paths 曲线平滑度
    Anti-aliasing setting Graphics Contexts 反锯齿设置
    Color Color and Color Spaces 颜色
    Alpha value (transparency) Color and Color Spaces 透明度
    Rendering intent Color and Color Spaces 渲染目标
    Color space Color and Color Spaces 颜色空间
    Text Text 文本
    Blend mode Paths and Bitmap images and Image masks 混合模式

    Quartz 2D Coordinate System

    A coordinate system, shown in Figure 1-4, defines the range of locations used to express the location and sizes of objects to be drawn on the page. You specify the location and size of graphics in the user-space coordinate system, or, more simply, the user space. Coordinates are defined as floating-point values.

    坐标系统定义是被绘制到Page上的对象的位置及大小范围,如图1-4所示。我们在用户空间坐标系统(user-space coordination system,简称用户空间)中指定图形的位置及大小。坐标值是用浮点数来定义的。

    Figure 1-4 The Quartz coordinate system

    Because different devices have different underlying imaging capabilities, the locations and sizes of graphics must be defined in a device-independent manner. For example, a screen display device might be capable of displaying no more than 96 pixels per inch, while a printer might be capable of displaying 300 pixels per inch. If you define the coordinate system at the device level (in this example, either 96 pixels or 300 pixels), objects drawn in that space cannot be reproduced on other devices without visible distortion. They will appear too large or too small.

    由于不同的设备有不同的图形功能,所以图像的位置及大小依赖于设备。例如,一个显示设备可能每英寸只能显示少于96个像素,而打印机可能每英寸能显示300个像素。如果在设备级别上定义坐标系统,则在一个设备上绘制的图形无法在其它设备上正常显示。

    Quartz accomplishes device independence with a separate coordinate system—user space—mapping it to the coordinate system of the output device—device space—using the current transformation matrix, or CTM. A matrix is a mathematical construct used to efficiently describe a set of related equations. 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).

    The current transformation matrix has a secondary purpose: It allows you to transform how objects are drawn. For example, to draw a box rotated by 45 degrees, you rotate the coordinate system of the page (the CTM) before you draw the box. Quartz draws to the output device using the rotated coordinate system.

    Quartz通过使用当前转换矩阵(current transformation matrix, CTM)将一个独立的坐标系统(user space)映射到输出设备的坐标系统(device space),以此来解决设备依赖问题。 CTM是一种特殊类型的矩阵(affine transform, 仿射矩阵),通过平移(translation)、旋转(rotation)、缩放(scale)操作将点从一个坐标空间映射到另外一个坐标空间。

    CTM还有另外一个目的:允许你通过转换来决定对象如何被绘制。例如,为了绘制一个旋转了45度的盒子,我们可以在绘制盒子之前旋转Page的坐标系统。Quartz使用旋转过的坐标系统来将盒子绘制到输出设备中。

    A point in user space is represented by a coordinate pair (x,y), where x represents the location along the horizontal axis (left and right) and y represents the vertical axis (up and down). The origin of the user coordinate space is the point (0,0). The origin is located at the lower-left corner of the page, as shown in Figure 1-4. In the default coordinate system for Quartz, the x-axis increases as it moves from the left toward the right of the page. The y-axis increases in value as it moves from the bottom toward the top of the page.

    用户空间的点用坐标对(x, y)来表示,(0, 0)表示坐标原点。Quartz中默认的坐标系统是:沿着x轴从左到右坐标值逐渐增大;沿着y轴从下到上坐标值逐渐增大。

    Some technologies set up their graphics contexts using a different default coordinate system than the one used by Quartz. Relative to Quartz, such a coordinate system is a modified coordinate system and must be compensated for when performing some Quartz drawing operations. The most common modified coordinate system places the origin in the upper-left corner of the context and changes the y-axis to point towards the bottom of the page. A few places where you might see this specific coordinate system used are the following:

    • In Mac OS X, a subclass of NSView that overrides its isFlipped
    • In iOS, a drawing context returned by an UIView
    • In iOS, a drawing context created by calling the UIGraphicsBeginImageContextWithOptions function.

    有一些技术在设置它们的graphics context时使用了不同于Quartz的默认坐标系统。相对于Quartz来说,这些坐标系统是修改的坐标系统(modified coordinate system),当在这些坐标系统中显示Quartz绘制的图形时,必须进行转换。最常见的一种修改的坐标系统是原点位于左上角,而沿着y轴从上到下坐标值逐渐增大我们可以在如下一些地方见到这种坐标系统:

    • 在Mac OS X中,重写过isFlipped方法以返回yes的NSView类的子类
    • 在IOS中,由UIView返回的绘图上下文
    • 在IOS中,通过调用UIGraphicsBeginImageContextWithOptions函数返回的绘图上下文

    The reason UIKit returns Quartz drawing contexts with modified coordinate systems is that UIKit uses a different default coordinate convention; it applies the transform to Quartz contexts it creates so that they match its conventions. If your application wants to use the same drawing routines to draw to both a UIView
    object and a PDF graphics context (which is created by Quartz and uses the default coordinate system), you need to apply a transform so that the PDF graphics context receives the same modified coordinate system. To do this, apply a transform that translates the origin to the upper-left corner of the PDF context and scales the y-coordinate by -1

    如果应用程序想以相同的绘制程序在一个UIView对象和PDF Graphics Context上进行绘制,需要做一个变换以使PDF Graphics Context使用与UIView相同的坐标系。要达到这一目的,只需要对PDF的上下文的原点做一个平移(移到左上角)和用-1对y坐标值进行缩放。图1-5显示了这种变换操作:

    Using a scaling transform to negate the y-coordinate alters some conventions in Quartz drawing. For example, if you call CGContextDrawImage
    to draw an image into the context, the image is modified by the transform when it is drawn into the destination. Similarly, path drawing routines accept parameters that specify whether an arc is drawn in a clockwise or counterclockwise direction in the default coordinate system. If a coordinate system is modified, the result is also modified, as if the image were reflected in a mirror. In Figure 1-5, passing the same parameters into Quartz results in a clockwise arc in the default coordinate system and a counterclockwise arc after the y-coordinate is negated by the transform.

    Figure 1-5 Modifying the coordinate system creates a mirrored image.

    It is up to your application to adjust any Quartz calls it makes to a context that has a transform applied to it. For example, if you want an image or PDF to draw correctly into a graphics context, your application may need to temporarily adjust the CTM of the graphics context. In iOS, if you use a UIImage object to wrap a CGImage object you create, you do not need to modify the CTM. The UIImage object automatically compensates for the modified coordinate system applied by UIKit.

    我们的应用程序负责调整Quartz调用以确保有一个转换应用到上下文中。例如,如果你想要一个图片或PDF正确的绘制到一个Graphics Context中,你的应用程序可能需要临时调整Graphics Context的CTM。在IOS中,如果使用UIImage对象来包裹创建的CGImage对象,可以不需要修改CTM。UIImage将自动进行补偿以适用UIKit的坐标系统。

    Important: The above discussion is essential to understand if you plan to write applications that directly target Quartz on iOS, but it is not sufficient. On iOS 3.2 and later, when UIKit creates a drawing context for your application, it also makes additional changes to the context to match the default UIKIt conventions. In particular, patterns and shadows, which are not affected by the CTM, are adjusted separately so that their conventions match UIKit’s coordinate system. In this case, there is no equivalent mechanism to the CTM that your application can use to change a context created by Quartz to match the behavior for a context provided by UIKit; your application must recognize the what kind of context it is drawing into and adjust its behavior to match the expectations of the context.

    重要:如果你打算在IOS上开发与Quartz相关的程序,了解以上所讨论的是很有用的,但不是必须的。在IOS 3.2及后续的版本中,当UIKit为你的应用程序创建一个绘图上下文时,也对上下文进行了额外的修改以匹配UIKit的约定。特别的,patterns和shadows(不被CTM影响)单独进行调整以匹配UIKit坐标系统。在这种情况下,没有一个等价的机制让CTM来转换Quartz和UIKit的上下文。我们必须认识到在什么样的上下文中进行绘制,并调整行为以匹配上下文的预期。

    Memory Management:Object Ownership

    Quartz uses the Core Foundation memory management model, in which objects are reference counted. When created, Core Foundation objects start out with a reference count of 1. You can increment the reference count by calling a function to retain the object, and decrement the reference count by calling a function to release the object. When the reference count is decremented to 0, the object is freed. This model allows objects to safely share references to other objects.
    There are a few simple rules to keep in mind:

    • If you create or copy an object, you own it, and therefore you must release it. That is, in general, if you obtain an object from a function with the words “Create” or “Copy” in its name, you must release the object when you’re done with it. Otherwise, a memory leak results.
    • If you obtain an object from a function that does not contain the words “Create” or “Copy” in its name, you do not own a reference to the object, and you must not release it. The object will be released by its owner at some point in the future.
    • If you do not own an object and you need to keep it around, you must retain it and release it when you’re done with it. You use the Quartz 2D functions specific to an object to retain and release that object. For example, if you receive a reference to a CGColorspace object, you use the functions CGColorSpaceRetain and CGColorSpaceRelease to retain and release the object as needed. You can also use the Core Foundation functions CFRetain and CFRelease, but you must be careful not to pass NULL to these functions.

    Quartz使用Core Foundation内存管理模型(引用计数)。所以,对象的创建与销毁与通常的方式是一样的。在Quartz中,需要记住如下一些规则:

    • 如果创建或拷贝一个对象,你将拥有它,因此你必须释放它。通常,如果使用含有”Create”或“Copy”单词的函数获取一个对象,当使用完后必须释放,否则将导致内存泄露。
    • 如果使用不含有”Create”或“Copy”单词的函数获取一个对象,你将不会拥有对象的引用,不需要释放它。这些对象将在未来的某个时间点被它的所有者释放。
    • 如果你不拥有一个对象而打算保持它,则必须retain它并且在不需要时release掉。可以使用Quartz 2D的函数来指定retain和release一个对象。例如,如果创建了一个CGColorspace对象,则使用函数CGColorSpaceRetain和CGColorSpaceRelease来retain和release对象。同样,可以使用Core Foundation的CFRetain和CFRelease,但是注意不能传递NULL值给这些函数。
    logo.png

    相关文章

      网友评论

          本文标题:Quartz 2D 编程指南一:Quartz 2D预览

          本文链接:https://www.haomeiwen.com/subject/mbhoxxtx.html