I need to crop the centre portion of an image to a rectangle of height 200 and width 250. There is no scroll view.
In all the solutions I found, there is a calculation like,
let scale = image.size.width / imageView.frame.width
and then multiplying x, y, height and width of the rect with the scale, before passing it to the cropping(to:) method, which will convert the rect from UIKit coordinates to core graphics coordinates.
My problem is, after doing these conversions and converting it to a UIImage, the cropped area is not the expected one.
I also tried,
let scale = max(image.size.width / imageView.frame.width, image.size.height / imageView.frame.height)
Still the resulting cropped area is off by around 100 points in the x and y axes. What am I missing here? Is there any additional calculation required?