< Previous PageNext Page > Hide TOC

Basics of Using Image I/O

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:

You can create image source and image destination objects from:

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.”

In this section:

Using the Image I/O Framework in Xcode
Supported Image Formats


Using the Image I/O Framework in Xcode

To add the Image I/O framework to an Xcode project:

  1. Open Xcode and create an application.

  2. Choose Project > Add to Project.

  3. Navigate to System/Library/Frameworks/ApplicationServices/. Then click Add.

  4. In the sheet that appears, click Add.

  5. Save the project.

Then, you’ll also need to 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. For the most up-to-date list of what Image I/O supports, you can call the these functions:

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);
Table 1-1  Common uniform type identifiers (UTIs) and image content type constants

Uniform type identifier

Image content type constant

public.image

kUTTypeImage

public.jpeg

kUTTypeJPEG

public.jpeg-2000

kUTTypeJPEG2000

public.tiff

kUTTypeTIFF

com.apple.pict

kUTTypePICT

com.compuserve.gif

kUTTypeGIF



< Previous PageNext Page > Hide TOC


© 2001, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-07-02)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.