iOS Developer Library

Developer

ApplicationServices Framework Reference CGImageSource Reference

Options
Deployment Target:

On This Page
Language:

CGImageSource Reference

CGImageSource objects, available in OS X v10.4 or later, abstract the data-reading task. An image source can read image data from a URL, a CFData object, or a data consumer.

After creating a CGImageSource object for the appropriate source, you can obtain images, thumbnails, image properties, and other image information using CGImageSource functions.

Functions

  • Updates an incremental image source with new data.

    Declaration

    Swift

    func CGImageSourceUpdateData(_ isrc: CGImageSource!, _ data: CFData!, _ final: Bool)

    Objective-C

    void CGImageSourceUpdateData ( CGImageSourceRef isrc, CFDataRef data, bool final );

    Parameters

    isrc

    An image source.

    data

    The data to add to the image source. Each time you call the function CGImageSourceUpdateData, the data parameter must contain all of the image file data accumulated so far.

    final

    A value that specifies whether the data is the final set. Pass true if it is, false otherwise.

    Import Statement

    import ImageIO

    Availability

    Available in iOS 4.0 and later.

  • Updates an incremental image source with a new data provider.

    Declaration

    Swift

    func CGImageSourceUpdateDataProvider(_ isrc: CGImageSource!, _ provider: CGDataProvider!, _ final: Bool)

    Objective-C

    void CGImageSourceUpdateDataProvider ( CGImageSourceRef isrc, CGDataProviderRef provider, bool final );

    Parameters

    isrc

    An image source.

    provider

    The new data provider. The new data provider must provide all the previous data supplied to the image source plus any additional new data.

    final

    A value that specifies whether the data is the final set. Pass true if it is, false otherwise.

    Import Statement

    import ImageIO

    Availability

    Available in iOS 4.0 and later.

  • Returns the unique type identifier of an image source opaque type.

    Declaration

    Swift

    func CGImageSourceGetTypeID() -> CFTypeID

    Objective-C

    CFTypeID CGImageSourceGetTypeID ( void );

    Return Value

    Returns the Core Foundation type ID for an image source.

    Discussion

    A type identifier is an integer that identifies the opaque type to which a Core Foundation object belongs. You use type IDs in various contexts, such as when you are operating on heterogeneous collections. Note that a CFType ID is different from a uniform type identifier (UTI).

    Import Statement

    import ImageIO

    Availability

    Available in iOS 4.0 and later.

  • Returns the uniform type identifier of the source container.

    Declaration

    Swift

    func CGImageSourceGetType(_ isrc: CGImageSource!) -> CFString!

    Objective-C

    CFStringRef CGImageSourceGetType ( CGImageSourceRef isrc );

    Parameters

    isrc

    An image source.

    Return Value

    The uniform type identifier of the image.

    Discussion

    The uniform type identifier (UTI) of the source container can be different from the type of the images in the container. For example, the .icns format supports embedded JPEG2000. The type of the source container is "com.apple.icns" but type of the images is JPEG2000.

    See Uniform Type Identifier Concepts in Uniform Type Identifiers Overview for a list of system-declared and third-party UTIs.

    Import Statement

    import ImageIO

    Availability

    Available in iOS 4.0 and later.

  • Returns an array of uniform type identifiers (UTIs) that are supported for image sources.

    Declaration

    Swift

    func CGImageSourceCopyTypeIdentifiers() -> CFArray!

    Objective-C

    CFArrayRef CGImageSourceCopyTypeIdentifiers ( void );

    Return Value

    Returns an array of the UTIs that are supported for image sources.

    Discussion

    See Uniform Type Identifiers Overview for a list of system-declared and third-party UTIs.

    Import Statement

    import ImageIO

    Availability

    Available in iOS 4.0 and later.

  • Returns the number of images (not including thumbnails) in the image source.

    Declaration

    Swift

    func CGImageSourceGetCount(_ isrc: CGImageSource!) -> UInt

    Objective-C

    size_t CGImageSourceGetCount ( CGImageSourceRef isrc );

    Parameters

    isrc

    An image source.

    Return Value

    The number of images. If the image source is a multilayered PSD file, the function returns 1.

    Discussion

    This function does not extract the layers of a PSD file.

    Import Statement

    import ImageIO

    Availability

    Available in iOS 4.0 and later.

  • Returns the properties of the image source.

    Declaration

    Swift

    func CGImageSourceCopyProperties(_ isrc: CGImageSource!, _ options: CFDictionary!) -> CFDictionary!

    Objective-C

    CFDictionaryRef CGImageSourceCopyProperties ( CGImageSourceRef isrc, CFDictionaryRef options );

    Parameters

    isrc

    An image source.

    options

    A dictionary you can use to request additional options. See Image Source Option Dictionary Keys for the keys you can supply.

    Return Value

    A dictionary that contains the properties associated with the image source container. See CGImageProperties Reference for a list of properties that can be in the dictionary.

    Discussion

    These properties apply to the container in general but not necessarily to any individual image contained in the image source.

    Import Statement

    import ImageIO

    Availability

    Available in iOS 4.0 and later.

  • Returns the properties of the image at a specified location in an image source.

    Declaration

    Swift

    func CGImageSourceCopyPropertiesAtIndex(_ isrc: CGImageSource!, _ index: UInt, _ options: CFDictionary!) -> CFDictionary!

    Objective-C

    CFDictionaryRef CGImageSourceCopyPropertiesAtIndex ( CGImageSourceRef isrc, size_t index, CFDictionaryRef options );

    Parameters

    isrc

    An image source.

    index

    The index of the image whose properties you want to obtain. The index is zero-based.

    options

    A dictionary you can use to request additional options. See “Image Source Option Dictionary Keys” for the keys you can supply.

    Return Value

    A dictionary that contains the properties associated with the image. See CGImageProperties Reference for a list of properties that can be in the dictionary.

    Import Statement

    import ImageIO

    Availability

    Available in iOS 4.0 and later.

  • Return the status of an image source.

    Declaration

    Swift

    func CGImageSourceGetStatus(_ isrc: CGImageSource!) -> CGImageSourceStatus

    Objective-C

    CGImageSourceStatus CGImageSourceGetStatus ( CGImageSourceRef isrc );

    Parameters

    isrc

    An image source.

    Return Value

    Returns the current status of the image source. See “Image Source Status” for a list of possible values.

    Discussion

    The status is particularly informative for incremental image sources, but may also be used by clients that provide non-incremental data.

    Import Statement

    import ImageIO

    Availability

    Available in iOS 4.0 and later.

  • Returns the current status of an image that is at a specified location in an image source.

    Declaration

    Swift

    func CGImageSourceGetStatusAtIndex(_ isrc: CGImageSource!, _ index: UInt) -> CGImageSourceStatus

    Objective-C

    CGImageSourceStatus CGImageSourceGetStatusAtIndex ( CGImageSourceRef isrc, size_t index );

    Parameters

    isrc

    An image source.

    index

    The index of the image whose status you want to obtain. The index is zero-based.

    Return Value

    Returns the current status of the image. See “Image Source Status” for a list of possible values.

    Discussion

    The status is particularly informative for incremental image sources, but may also be used by clients that provide non-incremental data.

    Import Statement

    import ImageIO

    Availability

    Available in iOS 4.0 and later.

Data Types

  • An opaque type that represents an image source.

    Declaration

    Swift

    typealias CGImageSourceRef = CGImageSource

    Objective-C

    typedef struct CGImageSource *CGImageSourceRef;

    Import Statement

    import ImageIO

    Availability

    Available in iOS 4.0 and later.

Constants

  • Status states for images and image sources.

    Declaration

    Swift

    struct CGImageSourceStatus { init(_ value: Int32) var value: Int32 }

    Objective-C

    enum CGImageSourceStatus { kCGImageStatusUnexpectedEOF = -5, kCGImageStatusInvalidData = -4, kCGImageStatusUnknownType = -3, kCGImageStatusReadingHeader = -2, kCGImageStatusIncomplete = -1, kCGImageStatusComplete = 0 }; typedef enum CGImageSourceStatus CGImageSourceStatus;

    Constants

    • kCGImageStatusUnexpectedEOF

      kCGImageStatusUnexpectedEOF

      The end of the file was encountered unexpectedly.

      Available in iOS 4.0 and later.

    • kCGImageStatusInvalidData

      kCGImageStatusInvalidData

      The data is not valid.

      Available in iOS 4.0 and later.

    • kCGImageStatusUnknownType

      kCGImageStatusUnknownType

      The image is an unknown type.

      Available in iOS 4.0 and later.

    • kCGImageStatusReadingHeader

      kCGImageStatusReadingHeader

      In the process of reading the header.

      Available in iOS 4.0 and later.

    • kCGImageStatusIncomplete

      kCGImageStatusIncomplete

      The operation is not complete

      Available in iOS 4.0 and later.

    • kCGImageStatusComplete

      kCGImageStatusComplete

      The operation is complete.

      Available in iOS 4.0 and later.

    Discussion

    These status values are returned by the functions CGImageSourceGetStatus and CGImageSourceGetStatusAtIndex.

    Import Statement

    import ImageIO

    Availability

    Available in iOS 4.0 and later.

  • Keys that you can include in the options dictionary to create an image source.

    Declaration

    Swift

    let kCGImageSourceTypeIdentifierHint: CFString! let kCGImageSourceShouldAllowFloat: CFString! let kCGImageSourceShouldCache: CFString! let kCGImageSourceCreateThumbnailFromImageIfAbsent: CFString! let kCGImageSourceCreateThumbnailFromImageAlways: CFString! let kCGImageSourceThumbnailMaxPixelSize: CFString! let kCGImageSourceCreateThumbnailWithTransform: CFString!

    Objective-C

    CFStringRef kCGImageSourceTypeIdentifierHint; CFStringRef kCGImageSourceShouldAllowFloat; CFStringRef kCGImageSourceShouldCache; CFStringRef kCGImageSourceCreateThumbnailFromImageIfAbsent; CFStringRef kCGImageSourceCreateThumbnailFromImageAlways; CFStringRef kCGImageSourceThumbnailMaxPixelSize; CFStringRef kCGImageSourceCreateThumbnailWithTransform

    Constants

    • kCGImageSourceTypeIdentifierHint

      kCGImageSourceTypeIdentifierHint

      The best guess of the uniform type identifier (UTI) for the format of the image source file. If specified, the value of this key must be a CFString object. This key can be provided in the options dictionary when you create a CGImageSource object.

      Available in iOS 4.0 and later.

    • kCGImageSourceShouldAllowFloat

      kCGImageSourceShouldAllowFloat

      Whether the image should be returned as a CGImage object that uses floating-point values, if supported by the file format. CGImage objects that use extended-range floating-point values may require additional processing to render in a pleasing manner. The value of this key must be a CFBoolean value. The default value is kCFBooleanFalse.

      Available in iOS 4.0 and later.

    • kCGImageSourceShouldCache

      kCGImageSourceShouldCache

      Whether the image should be cached in a decoded form. The value of this key must be a CFBoolean value. The default value is kCFBooleanFalse in 32-bit, kCFBooleanTrue in 64-bit. This key can be provided in the options dictionary that you can pass to the functions CGImageSourceCopyPropertiesAtIndex and CGImageSourceCreateImageAtIndex.

      Available in iOS 4.0 and later.

    • kCGImageSourceCreateThumbnailFromImageIfAbsent

      kCGImageSourceCreateThumbnailFromImageIfAbsent

      Whether a thumbnail should be automatically created for an image if a thumbnail isn't present in the image source file. The thumbnail is created from the full image, subject to the limit specified by kCGImageSourceThumbnailMaxPixelSize. If a maximum pixel size isn't specified, then the thumbnail is the size of the full image, which in most cases is not desirable. This key must be a CFBoolean value. The default value is kCFBooleanFalse. This key can be provided in the options dictionary that you pass to the function CGImageSourceCreateThumbnailAtIndex.

      Available in iOS 4.0 and later.

    • kCGImageSourceCreateThumbnailFromImageAlways

      kCGImageSourceCreateThumbnailFromImageAlways

      Whether a thumbnail should be created from the full image even if a thumbnail is present in the image source file. The thumbnail is created from the full image, subject to the limit specified by kCGImageSourceThumbnailMaxPixelSize. If a maximum pixel size isn't specified, then the thumbnail is the size of the full image, which probably isn't what you want. This key must be a CFBoolean value. The default value is kCFBooleanFalse. This key can be provided in the options dictionary that you can pass to the function CGImageSourceCreateThumbnailAtIndex.

      Available in iOS 4.0 and later.

    • kCGImageSourceThumbnailMaxPixelSize

      kCGImageSourceThumbnailMaxPixelSize

      The maximum width and height in pixels of a thumbnail. If this key is not specified, the width and height of a thumbnail is not limited and thumbnails may be as big as the image itself. If present, this key must be a CFNumber value. This key can be provided in the options dictionary that you pass to the function CGImageSourceCreateThumbnailAtIndex.

      Available in iOS 4.0 and later.

    • kCGImageSourceCreateThumbnailWithTransform

      kCGImageSourceCreateThumbnailWithTransform

      Whether the thumbnail should be rotated and scaled according to the orientation and pixel aspect ratio of the full image. The value of this key must be a CFBoolean value. The default value is kCFBooleanFalse.

      Available in iOS 4.0 and later.

    Discussion

    Except for kCGImageSourceTypeIdentifierHint, which you use when creating an image source, these constants specify options that you can set when creating an image from image source. Each constant is a key; you must supply the appropriate value when you add this option to the options dictionary.

    Import Statement