I used to resize the image using the following code, and it worked great with scale factor. Now with Swift 3 I can’t understand why the scale factor is not taken into account. The image changes, but the scale factor is not applied. You know why?
let layer = self.imageview.layer
UIGraphicsBeginImageContextWithOptions(layer.bounds.size, true, 0)
layer.render(in: UIGraphicsGetCurrentContext()!)
let scaledImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
print("SCALED IMAGE SIZE IS \(scaledImage!.size)")
print(scaledImage!.scale)
For example, if I take a screenshot on the iPhone 5, the image size will be 320 * 568. I used 640 * 1136 with exactly the same code. What can lead to the fact that the scale factor will not be applied?
When I print the image scale, it will print 1, 2 or 3 based on the resolution of the device, but will not be applied to the image taken from the context.