Quartz 2D 概述 1
The Core Graphics API is an object oriented API. To allow developers to use that API in as many environments as possible, however, the system implements it as a set of C routines. The API itself draws upon the object-oriented concepts of encapsulation, inheritance, and polymorphism. Because C doesn't directly support these concepts, Core Graphics uses opaque data types, in the place of classes, to support encapsulation and inheritance. To provide polymorphism, Core Graphics applies a naming convention to its routines.
CoreGraphics 对外提供 C 类型的调用接口,但是Core Graphics 本身建立在面向对象的 封装,继承,多态 上面。
It's important to realize that an object reference is not a pointer.
Core Graphics Objects have the names which end with the suffix Ref.
Encapsulation APIs:
Cocoa and the AppKit include a number of Objective-C classes that are implemented using the Quartz 2D API.
Alternative APIs :
1. for Python:
For example, the Core Graphics methodCGContextAddLineToPoint is reflected in the Python interface as the method addLineToPoint called on an instance of the Python CGContext class.
2. for HTML Canvas Tag:
evelopers also can encode Quartz 2D graphics into HTML content that is part of a Dashboard Widget or an HTML page displayed in Safari. 开发者可以在Dashboard Widget 和 Safari 的HTML 页面中嵌入 Quartz 2D 图形。step1:The HTML canvas Tag is the eara in which you would to draw Core Graphics. step2: After the drawing area has been identified, the HTML Document can draw that canvas using JavaScript to talk to it.
The JavaScript Code typically begin by asking the canvas for a context object, It then can call methods on that context to create graphics.
The Derivation of Quartz 2D:
Apple looked at the evolution of PostScript (adobe) and the PDF (Portable Document Format)strategy. Combining these elements with their own unique flair, Apple developed a new graphics library for Mac OS X that combined the richness of the Adobe Imaging Model with alpha channel support in the high-performance graphics library we know today as Quartz 2D.
---Understanding this legency can be an important part of understanding why the Quartz 2D image model behaves as it does. For example, Quartz 2D does not provide an easy mechanism form for erasering the graphics you have already drawn. The reason is that when you are drawing to a printer, the graphics may not be going to a frame buffer, and there is no way to eraser graphics. //// Instend of eraser graphics, in Quartz 2D you create a mask, or clip erea, and draw the graphics you want the user to see relying on the mask to remove partss of the image you don't want to display. This is a simple example but very illustrative of how the drawing model of the library can affect how it is used.
The Mac OS X Graphics Architecture OverView:
The challenge of the application designer is to decide at what level he needs to access the graphics system. It is a balance act between application complexity and performance.
OpenGL
OpenGL is also a valuable tool for accessing the full capabilities of the video card. OpenGL is a cross-platform standard.
Core Image
Core Image is a fliter-based image processing API. The system allow applications to bulit chains of filter (always directed, acyclic graph), combine them, and apply them to a image in a single step.
The kinds of filters found in Core Image are also often found in popular image processing applications such as Adobe Photoshop or The GIMP (GNU Image Manipulation Program).
Alpha Channel
The value of the Alpha Channel is interpreted as the level of transparency in the color.
The alpha channel also plays a role in another important Quartz 2D feature, antialiasing.
(Quartz uses a technique called sub-pixel sampling, The computer breaks each pixel into a number of small sub-pixel sampling, The sub-pixels are touched during drawing to decide the transparency level of the larger composite pixel.)