Crop image to a square according to the size of a UIView/CGRect

前端 未结 3 1695
栀梦
栀梦 2021-02-20 13:42

I have an implementation of AVCaptureSession and my goal is for the user to take a photo and only save the part of the image within the red square border, as shown below:

<
3条回答
  •  攒了一身酷
    2021-02-20 14:20

    Swift 3:

    let imageRef:CGImage = uncroppedImage.cgImage!.cropping(to: bounds)!
    let croppedImage:UIImage = UIImage(cgImage: imageRef)
    

提交回复
热议问题