vruzeda
vruzeda

Reputation: 1

Low-res image when using PHImageManager with fixed width and variable height

I'm using Photos Framework to request images to display in a UIImageView following user-defined parameters.

I'm basically using this code:

var options = PHImageRequestOptions()
options.version = PHImageRequestOptionsVersion.Current
options.deliveryMode =  PHImageRequestOptionsDeliveryMode.HighQualityFormat
options.resizeMode = PHImageRequestOptionsResizeMode.Exact
options.networkAccessAllowed = true

PHImageManager.defaultManager().requestImageForAsset(asset, targetSize: targetSize, contentMode: PHImageContentMode.AspectFill, options: options) { (result: UIImage!, info) -> Void in
    if !info[PHImageResultIsDegradedKey]!.boolValue {
        println("targetSize: \(targetSize)")
        println("asset.pixelWidth: \(asset.pixelWidth)")
        println("asset.pixelHeight: \(asset.pixelHeight)")
        println("result.size: \(result.size)")
    }
}

The user can select a "fit-width" or a "fit-height" option. In "fit-width", I use:

targetSize = CGSizeMake(width, PHImageManagerMaximumSize.height)

while in "fit-height", I use:

targetSize = CGSizeMake(PHImageManagerMaximumSize.width, height)

where width and height are obtained dynamically from the UIImageView's dimensions. My thought is that, by using PHImageManagerMaximumSize in the non-fixed dimension and PHImageContentMode.AspectFill for the contentMode, I'll get the largest image possible to fit my UIImageView.

"Fit-width" option:

targetSize: (2122.40673828125, -1.0)
asset.pixelWidth: 2048
asset.pixelHeight: 1536
result.size: (60.0, 45.0)

"Fit-height" option:

targetSize: (-1.0, 2241.7099609375)
asset.pixelWidth: 2048
asset.pixelHeight: 1536
result.size: (2048.0, 1536.0)

The problem happens in the first case: the user is seeing is a very low-res image when using the "fit-width" option.

Am I doing something wrong or is this an issue with PHImageManager?

Upvotes: 0

Views: 828

Answers (1)

jarora
jarora

Reputation: 5772

Try calling this method synchronously. This will give you the image of the right dimensions and quality straight away. Try this:

options.synchronous = true

Upvotes: 1

Related Questions