init(fromDictionaryRepresentation:)
Creates a depth data object from depth information such as that found in an image file.
Declaration
convenience init(fromDictionaryRepresentation imageSourceAuxDataInfoDictionary: [AnyHashable : Any]) throwsParameters
- imageSourceAuxDataInfoDictionary:
A dictionary of primitive depth-related information, in the format provided by the Cgimagesourcecopyauxiliarydatainfoatindex(_:_:_:) function.
Mentioned in
Discussion
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.
- (nullable AVDepthData *)depthDataFromImageData:(nonnull NSData *)imageData {
AVDepthData *depthData = nil;
CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL);
if (imageSource) {
NSDictionary *auxDataDictionary = (__bridge NSDictionary *)CGImageSourceCopyAuxiliaryDataInfoAtIndex(imageSource, 0, kCGImageAuxiliaryDataTypeDisparity);
if (auxDataDictionary) {
depthData = [AVDepthData depthDataFromDictionaryRepresentation:auxDataDictionary error:NULL];
}
CFRelease(imageSource);
}
return depthData;
}