[英]PhotoKit iOS8 - Retrieve image using the “PHImageFileURLKey”
[英]getting a poster frame from a video with PhotoKit (iOS8)
我想从视频资产中提取UIimage,以用作海报。 根据PHImageManager
的文档,我应该能够使用requestImageForAsset:targetSize:contentMode:options:resultHandler:
从文档中引用:
您可以对照片和视频资产使用此方法-对于视频资产,图像请求提供缩略图或海报框。
那不是我的经验。 使用带有视频资产的requestImageForAsset:targetSize:contentMode:options:resultHandler:
回调块始终为图像返回nil和nil错误。 返回的信息字典外观如下(我无法理解)
{ PHImageFileSandboxExtensionTokenKey = "31c0997752ae82ee32953503bd6d9a2436c50fac;00000000;00000000;000000000000001a;com.apple.app-sandbox.read;00000001;01000003;00000000000756cf;/private/var/mobile/Media/DCIM/100APPLE/IMG_0008.MOV"; PHImageFileURLKey = "file:///var/mobile/Media/DCIM/100APPLE/IMG_0008.MOV"; PHImageFileUTIKey = "dyn.ah62d4uv4ge804550"; PHImageResultDeliveredImageFormatKey = 9999; PHImageResultIsDegradedKey = 0; PHImageResultIsInCloudKey = 0; PHImageResultIsPlaceholderKey = 0; PHImageResultRequestIDKey = 26; PHImageResultWantedImageFormatKey = 9999; }
这是我在PHAsset
类别中编写的从下面的视频PHAsset中提取图像的方法。 有人能做这项工作吗?
@implementation PHAsset (util)
-(PHImageRequestID)fullSizeImage: (void(^)(UIImage *image, NSError *error)) resultHandler {
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
PHImageContentMode contentMode = PHImageContentModeAspectFill ;
PHImageManager *imageManager = [PHImageManager defaultManager] ;
CGSize targetSize = PHImageManagerMaximumSize ;
return [imageManager requestImageForAsset:self targetSize:targetSize contentMode:contentMode options:nil resultHandler:^(UIImage *result, NSDictionary *info) {
NSError *error = (NSError*)[info objectForKey:PHImageErrorKey];
if (result == nil) {
NSLog(@"ERROR while fetching fullSizeImage %@, info:\n%@", error, info);
}
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
resultHandler(result, error);
}];
}];
}
@end
替换后我就可以工作了
CGSize targetSize = PHImageManagerMaximumSize ;
与...
CGSize targetSize = CGSizeMake(self.pixelWidth*ratio, self.pixelHeight*ratio) ;
我还没有看到任何相关文档,所以可能是iOS8.0.x中的一个错误(在撰写本文时,iOS8.1 beta已可用,但我尚未对其进行测试)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.