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:

You can create image source and image destination objects from:

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:

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

Uniform type identifier

Image content type constant

public.image

kUTTypeImage

public.png

kUTTypePNG

public.jpeg

kUTTypeJPEG

public.jpeg-2000 (OS X only)

kUTTypeJPEG2000

public.tiff

kUTTypeTIFF

com.apple.pict (OS X only)

kUTTypePICT

com.compuserve.gif

kUTTypeGIF