Basics of Using Image I/O
The Image I/O framework provides opaque data types for reading image data from a source (CGImageSourceRef
) and writing image data to a destination (CGImageDestinationRef
). It supports a wide range of image formats, including the standard web formats, high dynamic range images, and raw camera data. Image I/O has many other features such as:
The fastest image decoders and encoders for the Mac platform
The ability to load images incrementally
Support for image metadata
Effective caching
You can create image source and image destination objects from:
URLs. Images whose location can be specified as a URL can act as a supplier or receiver of image data. In Image I/O, a URL is represented as the Core Foundation data type
CFURLRef
.The Core Foundation objects
CFDataRef
andCFMutableDataRef
.Quartz data consumer (
CGDataConsumerRef
) and data provider (CGDataProviderRef
) objects.
Using the Image I/O Framework in Your Application
Image I/O resides in the Application Services framework in OS X, and in the Image I/O framework in iOS. After adding the framework to your application, import the header file by including this statement:
#import <ImageIO/ImageIO.h>
Supported Image Formats
The Image I/O framework understands most of the common image file formats, such as JPEG, JPEG2000, RAW, TIFF, BMP, and PNG. Not all formats are supported on each platform. For the most up-to-date list of what Image I/O supports, you can call the these functions:
CGImageSourceCopyTypeIdentifiers
returns an array of the Uniform Type Identifiers (UTIs) that Image I/O supports as image sources.CGImageDestinationCopyTypeIdentifiers
returns an array of the uniform type identifiers (UTIs) that Image I/O supports as image destinations.
You can then use the CFShow
function to print the array to the debugger console in Xcode, as shown in Listing 1-1. The strings in the array returned by these functions take the form of com.apple.pict
, public.jpeg
, public.tiff
, and so on. Table 1-1 lists the UTIs for many common image file formats. OS X and iOS define constants for most common image file formats; The full set of constants are declared in the UTCoreTypes.h
header file. You can use these constants when you need to specify an image type, either as a hint for an image source (kCGImageSourceTypeIdentifierHint
) or as an image type for an image destination.
Listing 1-1 Getting and printing supported UTIs
CFArrayRef mySourceTypes = CGImageSourceCopyTypeIdentifiers(); |
CFShow(mySourceTypes); |
CFArrayRef myDestinationTypes = CGImageDestinationCopyTypeIdentifiers(); |
CFShow(myDestinationTypes); |
Uniform type identifier | Image content type constant |
---|---|
public.image |
|
public.png |
|
public.jpeg |
|
public.jpeg-2000 (OS X only) |
|
public.tiff |
|
com.apple.pict (OS X only) |
|
com.compuserve.gif |
|
Copyright © 2001, 2016 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2016-09-13