The Image I/O framework, available in Mac OS X v10.4 or later, 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
and CFMutableDataRef
.
Quartz data consumer (CGDataConsumerRef
) and data provider (CGDataProviderRef
) objects.
The Image I/O framework can be used by Cocoa or Carbon applications. Image I/O resides in the Application Services framework, so Carbon projects created with Xcode have its functionality available automatically. If you are creating a Cocoa project, you need to follow the steps in “Using the Image I/O Framework in Xcode.”
Using the Image I/O Framework in Xcode
Supported Image Formats
To add the Image I/O framework to an Xcode project:
Open Xcode and create an application.
Choose Project > Add to Project.
Navigate to System/Library/Frameworks/ApplicationServices/. Then click Add.
In the sheet that appears, click Add.
Save the project.
Then, you’ll also need to import the header file by including this statement:
#import <ImageIO/ImageIO.h>
The Image I/O framework understands most of the common image file formats, such as JPEG, JPEG2000, RAW, TIFF, BMP, and PNG. 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. The Launch Services framework declares constants for many UTIs; Table 1-1 lists some of them. (The full set of constants are declared in the LaunchServices/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. See also Uniform Type Identifiers Overview.
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.jpeg |
|
public.jpeg-2000 |
|
public.tiff |
|
com.apple.pict |
|
com.compuserve.gif |
|
© 2001, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-07-02)