iOS 8照相工具包。从iCloud照片共享相册获取最大大小的图像
如何从iСloud访问全尺寸图像?每次我试着拍这张照片时,我得到的图像大小是256x342。我也看不到进展 代码:iOS 8照相工具包。从iCloud照片共享相册获取最大大小的图像,ios,objective-c,frameworks,ios8,Ios,Objective C,Frameworks,Ios8,如何从iСloud访问全尺寸图像?每次我试着拍这张照片时,我得到的图像大小是256x342。我也看不到进展 代码: 在我单击照片应用程序中的图片之前,此图片的质量将很差。但只要我点击图片,它就会下载到设备上,并将具有全尺寸质量。我认为下面应该获得全分辨率图像数据: [manager requestImageDataForAsset:asset options:options resultHand
在我单击照片应用程序中的图片之前,此图片的质量将很差。但只要我点击图片,它就会下载到设备上,并将具有全尺寸质量。我认为下面应该获得全分辨率图像数据:
[manager requestImageDataForAsset:asset
options:options
resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info)
{
UIImage *image = [UIImage imageWithData:imageData];
//...
}];
WWDC视频中介绍了整个照片框架(PhotoKit):
希望这有帮助
编辑:
resultHandler可以调用两次。我在30:00左右链接到的视频中对此进行了解释。可能是因为您只获得了缩略图,而完整图像将在第二次调用时出现。我遇到了一些相同的问题。这不是一个bug就是糟糕的文档。我已经能够通过指定2000x2000的请求大小来绕过这个问题。问题是,我确实得到了完整大小的图像,但有时它会被标记为降级,所以我一直在等待一个不同的图像,而这从来没有发生过。这就是我为解决这些问题所做的
self.selectedAsset = asset;
self.collectionView.allowsSelection = NO;
PHImageRequestOptions* options = [[[PHImageRequestOptions alloc] init] autorelease];
options.synchronous = NO;
options.version = PHImageRequestOptionsVersionCurrent;
options.deliveryMode = PHImageRequestOptionsDeliveryModeOpportunistic;
options.resizeMode = PHImageRequestOptionsResizeModeNone;
options.networkAccessAllowed = YES;
options.progressHandler = ^(double progress,NSError *error,BOOL* stop, NSDictionary* dict) {
NSLog(@"progress %lf",progress); //never gets called
};
[self.delegate choosePhotoCollectionVCIsGettingPhoto:YES]; //show activity indicator
__block BOOL isStillLookingForPhoto = YES;
currentImageRequestId = [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:CGSizeMake(2000, 2000) contentMode:PHImageContentModeAspectFill options:options resultHandler:^(UIImage *result, NSDictionary *info) {
NSLog(@"result size:%@",NSStringFromCGSize(result.size));
BOOL isRealDealForSure = NO;
NSNumber* n = info[@"PHImageResultIsPlaceholderKey"]; //undocumented key so I don't count on it
if (n != nil && [n boolValue] == NO){
isRealDealForSure = YES;
}
if([info[PHImageResultIsInCloudKey] boolValue]){
NSLog(@"image is in the cloud"); //never seen this. (because I allowed network access)
}
else if([info[PHImageResultIsDegradedKey] boolValue] && !isRealDealForSure){
//do something with the small image...but keep waiting
[self.delegate choosePhotoCollectionVCPreviewSmallPhoto:result];
self.collectionView.allowsSelection = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ //random time of 3 seconds to get the full resolution in case the degraded key is lying to me. The user can move on but we will keep waiting.
if(isStillLookingForPhoto){
self.selectedImage = result;
[self.delegate choosePhotoCollectionVCPreviewFullPhoto:self.selectedImage]; //remove activity indicator and let the user move on
}
});
}
else {
//do something with the full result and get rid of activity indicator.
if(asset == self.selectedAsset){
isStillLookingForPhoto = NO;
self.selectedImage = result;
[self.delegate choosePhotoCollectionVCPreviewFullPhoto:self.selectedImage];
self.collectionView.allowsSelection = YES;
}
else {
NSLog(@"ignored asset because another was pressed");
}
}
}];
我相信这与您设置PhimageRequestOptionsDeliveryModeOpportunity有关。 请注意,异步模式(默认)甚至不支持这一点。
请尝试PhImageRequestOptions DeliveryModeHighQualityFormat intead。要获取全尺寸图像,需要查看信息列表。 我使用它来测试返回的结果是完整映像还是降级版本
if ([[info valueForKey:@"PHImageResultIsDegradedKey"]integerValue]==0){
// Do something with the FULL SIZED image
} else {
// Do something with the regraded image
}
或者你可以用这个来检查你是否得到了你想要的东西
if ([[info valueForKey:@"PHImageResultWantedImageFormatKey"]integerValue]==[[info valueForKey:@"PHImageResultDeliveredImageFormatKey"]integerValue]){
// Do something with the FULL SIZED image
} else {
// Do something with the regraded image
}
还有许多其他未记录但有用的密钥,例如
玩得开心。
LinassesNo,仍然可以看到大小{256342}方向0刻度1.000000,此处相同。我还尝试了RequestContentInputingWithOptions路由,指定允许的networkAccessAllowed。它总是给我低分辨率版本已经在我的设备上,除非我手动去查看照片中的图像事先。看起来像个bug,但我很高兴被证明是错的。resultHandler可以调用两次。我在30:00左右链接到的视频中对此进行了解释。可能是你只得到了缩略图,完整的图像将在第二次调用时出现。谢谢你指出这一点。这是视频中的一个重要细节,目前未出现在PHImageManager的文档中。但是我自己还没有尝试过。为了回答您关于为什么进度不更新的问题,您需要在进度处理程序中调度到主队列。我提交了一份BR文件,苹果最近修复了他们的SamplePhotosApp来做这件事。我的Mac电脑上从iPhoto/Photos同步的相册有这个问题。不管我做什么,上面提到的照片的分辨率只有256x342:(这张照片有什么新闻吗?还是有问题,而且这似乎只发生在PhotoStreams的照片上,而不是普通的iCloud照片库相册。
if ([[info valueForKey:@"PHImageResultWantedImageFormatKey"]integerValue]==[[info valueForKey:@"PHImageResultDeliveredImageFormatKey"]integerValue]){
// Do something with the FULL SIZED image
} else {
// Do something with the regraded image
}
PHImageFileOrientationKey = 3;
PHImageFileSandboxExtensionTokenKey = "/private/var/mobile/Media/DCIM/100APPLE/IMG_0780.JPG";
PHImageFileURLKey = "file:///var/mobile/Media/DCIM/100APPLE/IMG_0780.JPG";
PHImageFileUTIKey = "public.jpeg";
PHImageResultDeliveredImageFormatKey = 9999;
PHImageResultIsDegradedKey = 0;
PHImageResultIsInCloudKey = 0;
PHImageResultIsPlaceholderKey = 0;
PHImageResultRequestIDKey = 1;
PHImageResultWantedImageFormatKey = 9999;