Does PHImageManager return images in pixel or point size for 2x and 3x screens? Does PHImageManager return images in pixel or point size for 2x and 3x screens? swift swift

Does PHImageManager return images in pixel or point size for 2x and 3x screens?


According to my experiments with PHImageManageryou 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...        })


It's hard to tell from your code whether you realize that the resultHandler will be called multiple times. The first time it is called, you may get a low-resolution low-quality image. But eventually it will be called with a correctly scaled image.