I am implementing a image cropper which will crop image captured from the camera. Here is the actual result and expected result of the UI.
I followed this answer to get the desired visible image frame.
And after this, below is my code to crop the image using the visible frame:
func crop(_ rect: CGRect) -> UIImage {
if imagepicked.scale > 1.0 {
_ = CGRect(x: CGFloat(rect.origin.x * imagepicked.scale), y: CGFloat(rect.origin.y * imagepicked.scale), width: CGFloat(rect.size.width * imagepicked.scale)*2, height: CGFloat(rect.size.height * imagepicked.scale)*2)
}
let imageRef: CGImage? = imagepicked.cgImage?.cropping(to: rect)
let result = UIImage(cgImage: imageRef!, scale: imagepicked.scale, orientation: imagepicked.imageOrientation)
return result
}
but I am not getting the expected result.