Mac Developer Library

Developer

Image I/O Reference Collection CGImageSource Reference

Options
Deployment Target:

On This Page
Language:

CGImageSource Reference

CGImageSource objects 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.

    Availability

    Available in OS X version 10.4 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.

    Availability

    Available in OS X version 10.4 and later.

Data Types

  • An opaque type that represents an image source.

    Declaration

    Swift

    class CGImageSource { }

    Objective-C

    typedef struct CGImageSource *CGImageSourceRef;

    Import Statement

    Objective-C

    @import ImageIO;

    Swift

    import ImageIO

    Availability

    Available in OS X v10.4 and later.

Constants

  • Status states for images and image sources.

    Declaration

    Swift

    enum CGImageSourceStatus : Int32 { case StatusUnexpectedEOF case StatusInvalidData case StatusUnknownType case StatusReadingHeader case StatusIncomplete case StatusComplete }

    Objective-C

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

    Constants

    • StatusUnexpectedEOF

      kCGImageStatusUnexpectedEOF

      The end of the file was encountered unexpectedly.

      Available in OS X v10.4 and later.

    • StatusInvalidData

      kCGImageStatusInvalidData

      The data is not valid.

      Available in OS X v10.4 and later.

    • StatusUnknownType

      kCGImageStatusUnknownType

      The image is an unknown type.

      Available in OS X v10.4 and later.

    • StatusReadingHeader

      kCGImageStatusReadingHeader

      In the process of reading the header.

      Available in OS X v10.4 and later.

    • StatusIncomplete

      kCGImageStatusIncomplete

      The operation is not complete

      Available in OS X v10.4 and later.

    • StatusComplete

      kCGImageStatusComplete

      The operation is complete.

      Available in OS X v10.4 and later.

    Discussion

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

    Import Statement

    Objective-C

    @import ImageIO;

    Swift

    import ImageIO

    Availability

    Available in OS X v10.4 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 OS X v10.4 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 OS X v10.4 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 OS X v10.4 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 OS X v10.4 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 OS X v10.4 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 OS X v10.4 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 OS X v10.4 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.