Search code examples
iosswiftuiimageviewuiimagepickercontroller

How to crop image from camera preview view in swift 3?


I have a camera view and top of that I placed one blue rectangle line imageview.

enter image description here

My Questions is, when I press the capture button I have to save the image whatever is inside the rectangle area. I tried with below mentioned code but it doesn't crop that area.

let cgImage = image.cgImage
let croppedCGImage: CGImage = cgImage!.cropping(to: self.m_TrimArea.frame)!
let uiImage = UIImage(cgImage: croppedCGImage)

Here self.m_TrimArea is an imageview which holds the blue rectangle line. Please give some guidance to achieve this.


Solution

  • I would suggest you use the following pod. https://cocoapods.org/pods/Toucan