I'm loading images from the camera roll via PHImageManager, but the returned images are not retina resolution. Do I have to provide a multiplier myself for 2x and 3x or do I have something wrong?
Here is my code:
class ReviewableImageView: UIImageView {
...unrelated code
imageRequestOptions = PHImageRequestOptions()
imageRequestOptions.deliveryMode = .HighQualityFormat
imageRequestOptions.resizeMode = .Exact
...unrelated code
self.contentMode = .ScaleAspectFit
self.backgroundColor = UIColor.clearColor()
self.userInteractionEnabled = true
... unrelated code
func reloadImage(){
let imageManager = PHCachingImageManager()//PHImageManager()
imageManager.requestImageForAsset(self.imageAsset,
targetSize: self.frame.size,
contentMode: .AspectFit,
options: imageRequestOptions,
resultHandler: { (image: UIImage!, info: [NSObject : AnyObject]!) in
self.image = image
})
}
}
According to my experiments with PHImageManager
you must provide a targetSize
in pixels. For example, imagine you wanna request an image with the size 400x800 px. For this case you can set the target size like the following:
// Set target size.
let targetSize = CGSizeMake(400, 800)
Regarding your code example, in the Apple's docs stated that:
The coordinates of the frame rectangle are always specified in points.
So to set the correct target size in this case you can use code similar to the following:
// Get scale factor associated with the screen.
let scale = UIScreen.mainScreen().scale
// Request the image.
imageManager.requestImageForAsset(self.imageAsset,
targetSize: CGSizeMake(self.frame.size.width * scale, self.frame.size.height * scale),
contentMode: .AspectFit,
options: imageRequestOptions,
resultHandler: { (image, info) -> Void in
// Handle the result here...
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With