When I take a screenshot and grab the preview thats automatically placed in the bottom left hand corner of the device, the image in my action extension has a height/width that’s divided by 3 (device scale) which is causing some issues with my app. I tried scaling the image by a factor of 3 but the action extension never opens.
If I take a screenshot, let the preview go away, then initiate my action extension with the same photo but from the Photos app, everything works as expected.
I’m using an iPhone 14 Pro and expect the image to be 1179x2556 with a scale of 1. Instead I’m getting 393x852 with a scale of 3.
Does anyone know why the preview image is smaller or how I can scale it up in my action extension?
Turns out I needed to explicitly pass a UIGraphicsImageRendererFormat with a scale of 1 to the UIGraphicsImageRenderer. Then multiplying the image size by image scale works as expected.
extension UIImage {
func resized(to size: CGSize) -> UIImage {
let format = UIGraphicsImageRendererFormat()
format.scale = 1
return UIGraphicsImageRenderer(size: size, format: format).image { _ in
draw(in: CGRect(origin: .zero, size: size))
}
}
}
let size = CGSize(
width: image.size.width * image.scale,
height: image.size.height * image.scale
)
let screenshot = image.resized(to: size)