Contents

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]) throws

Parameters

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;
}

See Also

Creating depth data