iOS 8 PhotoKit。从iCloud照片共享相册中获取最大尺寸的图像 [英] iOS 8 PhotoKit. Get maximum-size image from iCloud Photo Sharing albums
问题描述
如何从iСloud访问全尺寸图像?每次我试图获得这张照片,我得到的图像大小为256x342。我也看不到进展。
代码:
PHFetchResult * result = [PHAsset fetchAssetsWithLocalIdentifiers: [assetIdentifier]选项:无];
PHImageManager * manager = [PHImageManager defaultManager];
[结果enumerateObjectsUsingBlock:^(PHAsset * asset,NSUInteger idx,BOOL * stop){
PHImageRequestOptions * options = [[PHImageRequestOptions alloc] init];
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
options.synchronous = YES;
options.networkAccessAllowed = YES;
options.progressHandler = ^(double progress,NSError * error,BOOL * stop,NSDictionary * info){
NSLog(@%f,progress);
};
[manager requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:options resultHandler:^(UIImage * resultImage,NSDictionary * info)
{
UIImage * image = resultImage;
NSLog(@%@,NSStringFromCGSize(resultImage.size));
}];
}];
直到我点击Photo应用程序中的图片,这张图片的质量会很差。但是,只要我点击图片,它就会下载到设备上,并且将具有全尺寸质量。 下面应该得到完整分辨率的图像数据:
[manager requestImageDataForAsset:资产
options:options
resultHandler:^(NSData * imageData,NSString * dataUTI,UIImageOrientation orientation,NSDictionary * info)
{
UIImage * image = [UIImage imageWithData:imageData];
// ...
}];
整个Photos Framework(PhotoKit)都包含在WWDC视频中:https://developer.apple.com/videos/wwdc/2014/#511
希望这会有所帮助。
编辑:
resultHandler可以被调用两次。我在30点左右链接到的视频中对此进行了解释。可能是因为你只能得到缩略图,第二次调用完整的图像。
How get access to the full-size images from iСloud? Every time I try to get this picture, I get image size 256x342. I not see progress too.
Code:
PHFetchResult *result = [PHAsset fetchAssetsWithLocalIdentifiers:@[assetIdentifier] options:nil];
PHImageManager *manager = [PHImageManager defaultManager];
[result enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
options.synchronous = YES;
options.networkAccessAllowed = YES;
options.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
NSLog(@"%f", progress);
};
[manager requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:options resultHandler:^(UIImage *resultImage, NSDictionary *info)
{
UIImage *image = resultImage;
NSLog(@"%@", NSStringFromCGSize(resultImage.size));
}];
}];
Until I click the picture in Photo app, this picture will be of poor quality. But as soon as I click on the picture, it downloaded on the device and will be full-size quality.
I think the below should get the full resolution image data:
[manager requestImageDataForAsset:asset
options:options
resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info)
{
UIImage *image = [UIImage imageWithData:imageData];
//...
}];
The entire Photos Framework (PhotoKit) is covered in the WWDC video: https://developer.apple.com/videos/wwdc/2014/#511
Hope this helps.
Edit:
The resultHandler can be called twice. This is explained in the video I linked to at around 30:00. Could be that you are only getting the thumbnail and the full image will come with the second time its called.
这篇关于iOS 8 PhotoKit。从iCloud照片共享相册中获取最大尺寸的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!