MingGong Zhu
MingGong Zhu

Reputation: 63

PHImageManager.requestImageForAsset returns low-res image in iOS swift

I'm using Photos framework to handle images in iOS swift. When I try to get the image by using PHImageManager.defaultImanager().requestImageForAsset(), it works fine for most of images. That function returns two values: one is of scale 1, another is of scale 2. The image of scale 1 is high-res image, and the image of scale 2 is low-res image. But regarding some of images, it returns only low-res one.

Does anyone know how to get high-res image for every PHAsset ?

Here are my codes:

Regarding some of images, it doesn't return the image of scale 1 (high-res), so it doesn't go through subFuncForDisplayCurrentImage()

    var targetSize:CGSize = CGSizeMake(UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height)
    var itemOptions = PHImageRequestOptions()
    itemOptions.networkAccessAllowed = true

    PHImageManager.defaultManager().requestImageForAsset(asset, targetSize: targetSize, contentMode: PHImageContentMode.AspectFit, options: itemOptions) { (result:UIImage!, info:[NSObject : AnyObject]!) -> Void in
        if result != nil && result.scale == 1 {
            self.subFuncForDisplayCurrentImage(result, ID: (asset?.localIdentifier)!)
        }
    }

Upvotes: 1

Views: 6022

Answers (3)

Herbert Bay
Herbert Bay

Reputation: 225

For iOS 13, the method returns first a low-res version of the image. See Apple documentation

For an asynchronous request, Photos may call your result handler block more than once. Photos first calls the block to provide a low-quality image suitable for displaying temporarily while it prepares a high-quality image. (If low-quality image data is immediately available, the first call may occur before the method returns.) When the high-quality image is ready, Photos calls your result handler again to provide it. If the image manager has already cached the requested image at full quality, Photos calls your result handler only once. The PHImageResultIsDegradedKey key in the result handler’s info parameter indicates when Photos is providing a temporary low-quality image.

Upvotes: 2

Deepak Patil
Deepak Patil

Reputation: 71

To get high quality images add below code

itemOptions.deliveryMode = PHImageRequestOptionsDeliveryMode.HighQualityFormat

Upvotes: 3

gabbler
gabbler

Reputation: 13766

You may want to specify PHImageRequestOptionsDeliveryModeHighQualityFormat as the deliver mode.

In the document: PHImageRequestOptionsDeliveryMode, it states:

Photos provides only the highest-quality image available, regardless of how much time it takes to load.

Upvotes: 5

Related Questions