Creates a depth data object from depth information such as that found in an image file.


convenience init(fromDictionaryRepresentation imageSourceAuxDataInfoDictionary: [AnyHashable : Any]) throws



A dictionary of primitive depth-related information, in the format provided by the CGImageSourceCopyAuxiliaryDataInfoAtIndex(_:_:_:) function.


When using CGImageSource functions to read from a HEIF, JPEG, or DNG file containing depth data (as well as image data), you can use the CGImageSourceCopyAuxiliaryDataInfoAtIndex(_:_:_:) function to load primitive depth map information, then use this initializer to create an AVDepthData object, as shown below.

func depthData(from imageData: Data) -> AVDepthData? {
    guard let imageSource = CGImageSourceCreateWithData(imageData as CFData, nil)
        else { return nil }
    guard let auxiliaryData = CGImageSourceCopyAuxiliaryDataInfoAtIndex(imageSource, 0, kCGImageAuxiliaryDataTypeDisparity) as? [AnyHashable: Any]
        else { return nil }
    guard let depthData = try? AVDepthData(fromDictionaryRepresentation: auxiliaryData)
        else { return nil }
    return depthData

See Also

Creating Depth Data

Creating Auxiliary Depth Data Manually

Generate a depth image and attach it to your own image.

func dictionaryRepresentation(forAuxiliaryDataType: AutoreleasingUnsafeMutablePointer<NSString?>?) -> [AnyHashable : Any]?

Returns a dictionary representation of the depth data suitable for writing into an image file.