【发布时间】:2020-01-14 23:39:48
【问题描述】:
我尝试从 PHAsset 获取视差图或深度图。我找到了从加载 PHImageMager 的图像中获取地图并实现它的示例:
- (AVDepthData*)getDepthDataFromSource:(CGImageSourceRef)source
{
NSDictionary* depthData = CFBridgingRelease(CGImageSourceCopyAuxiliaryDataInfoAtIndex(source, 0, kCGImageAuxiliaryDataTypeDepth));
if (!depthData){
depthData = CFBridgingRelease(CGImageSourceCopyAuxiliaryDataInfoAtIndex(source, 0, kCGImageAuxiliaryDataTypeDisparity));
}
if (!depthDat)
return nil; //code returns here
NSError* creationError = nil;
AVDepthData* data = [AVDepthData depthDataFromDictionaryRepresentation:depthData
error:&creationError];
return data;
}
//from a image
[[PHImageManager defaultManager] requestImageForAsset:asset
targetSize:size
contentMode:contentMode
options:requestOptions
resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
CGImageRef im = image.CGImage;
CGImageSourceRef source = CGImageSourceCreateWithDataProvider(CGImageGetDataProvider(im), (CFDictionaryRef)@{});
AVDepthData* data = [self getDepthDataFromSource:source];//data is nil
if (source != nil)
{
CFRelease(source);
}
}];
//from a data
PHImageRequestOptions* imageDataRequestOptions = [[PHImageRequestOptions alloc] init];
imageDataRequestOptions.networkAccessAllowed = YES;
imageDataRequestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
PHImageRequestID requestId = [[PHImageManager defaultManager] requestImageDataForAsset:asset
options:imageDataRequestOptions
resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)imageData, (CFDictionaryRef)@{});
AVDepthData* data = [self getDepthDataFromSource:source];//data is nil
if (source != nil)
{
CFRelease(source);
}
}
];
//from full resolution image
__block FADisparityDataReader* selfStong = self;
PHContentEditingInputRequestOptions* options = [[PHContentEditingInputRequestOptions alloc] init];
options.networkAccessAllowed = YES;
[asset requestContentEditingInputWithOptions:options
completionHandler:^(PHContentEditingInput * _Nullable contentEditingInput, NSDictionary * _Nonnull info) {
NSURL* fullSizePath = [contentEditingInput fullSizeImageURL];
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)fullSizePath, (CFDictionaryRef)@{});
@onExit{
CFRelease(source);
};
AVDepthData* data = [self readDepthDataFromSource:source]; //data is not nil
complition(data);
}];
我只在requestContentEditingInputWithOptions 块中获取深度数据,但它太长了,我相信我可以从 PHImageManager 图像中获取深度图。
如何从 PHImageManager 获取数据?
【问题讨论】:
-
偶然发现这个...不是因为您在 if (!depthDat) { 行中检查 depthDat 而不是 depthData?
标签: ios objective-c image