Search code examples
iosiphoneimageios8photokit

How to get requested image size for iOS8 PhotoKit?


I am using the code below for fetching an image:

[[PHImageManager defaultManager] requestImageForAsset:asset 
targetSize:CGSizeMake(800, 600) 
contentMode:PHImageContentModeAspectFill 
options:options 
resultHandler:^(UIImage *result, NSDictionary *info) {
    NSLog(@"size:%@",NSStringFromCGSize(result.size));                
}];

I'm requesting an image size of 800 x 600, but I'm getting an image size of 45 x 60, which is very poor-quality.

How can i get the requested image size using PhotoKit?


Solution

  • I was able to get image of size 800*600 using below code:

    PHImageRequestOptions* options = [[[PHImageRequestOptions alloc] init] autorelease];
    options.version = PHImageRequestOptionsVersionCurrent;
    options.deliveryMode =  PHImageRequestOptionsDeliveryModeHighQualityFormat;
    options.resizeMode = PHImageRequestOptionsResizeModeExact;
    
    [PHImageManager defaultManager]
    requestImageForAsset:(PHAsset *)asset
    targetSize:CGSizeMake(800, 600)
    contentMode:PHImageContentModeAspectFit
    options:options
    resultHandler:^(UIImage *result, NSDictionary *info) {
       NSLog(@"Image size:%@",NSStringFromCGSize(result.size));
    }];
    

    And if you want to get full size image you can use PHImageManagerMaximumSize as targetSize.