【Data Management in Quartz 2D】
The preferred way to read and write image data is to use the Image I/O framework. See Image I/O Programming Guide for more information on the CGImageSourceRef and CGImageDestinationRef opaque data types.
Image sources and data providers abstract the data-access task and eliminate the need for applications to manage data through a raw memory buffer.
【Moving Data into Quartz 2D】
image sources are the preferred way to move image data into Quartz. An image source represents a wide variety of image data. An image source can contain more than one image, thumbnail images, and properties for each image and the image file. After you have a CGImageSourceRef, you can accomplish these tasks:
- Create images (CGImageRef) using the functions CGImageSourceCreateImageAtIndex, CGImageSourceCreateThumbnailAtIndex, or CGImageSourceCreateIncremental. A CGImageRef data type represents a single Quartz image.
- Add content to an image source using the functions CGImageSourceUpdateData or CGImageSourceUpdateDataProvider.
- Obtain information from an image source using the functions CGImageSourceGetCount , CGImageSourceCopyProperties, and CGImageSourceCopyTypeIdentifiers.
Functions that move data into Quartz 2D:
【Moving Data out of Quartz 2D】
An image destination is the preferred way to move image data out of Quartz. Similar to image sources, an image destination can represent a variety of image data, from a single image to a destination that contains multiple images, thumbnail images, and properties for each image or for the image file. After you have a CGImageDestinationRef, you can accomplish these tasks:
- Add images (CGImageRef) to a destination using the functions CGImageDestinationAddImage or CGImageDestinationAddImageFromSource. A CGImageRef data type represents a single Quartz image.
- Set properties using the function CGImageDestinationSetProperties.
- Obtain information from an image destination using the functions CGImageDestinationCopyTypeIdentifiers or CGImageDestinationGetTypeID.
Functions that move data out of Quartz 2D:
【小结】
1、CGDataComsumer对应CGDataProvider,是一种比较老的框架。位于最底层,直接与硬盘文件打交道。
2、CGImageDestination对应CGImageSource,在1.之上,是新型框架。现在开发IOS应该抛弃1.中所述,直接使用本条中技术。此条内容包括图像HEADER & BODY。
3、CGImage对应图像BODY,可通过CGImageSource获取。
4、CIImage是CoreImage框架,用于对图片对进特殊处理。
【Core Image】
The Quartz 2D API does not provide any functions that package Quartz images as Core Image images, but Core Image does. The following Core Image methods create a Core Image image from either a Quartz image or a Quartz layer (CGLayerRef). You can use them to move Quartz 2D data to Core Image.
- imageWithCGImage:
- imageWithCGImage:options:
- imageWithCGLayer:
- imageWithCGLayer:options:
The following Core Image methods return a Quartz image from a Core Image image. You can use them to move a processed image back into Quartz 2D:
- createCGImage:fromRect:
- createCGLayerWithSize:info: