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

前端 未结 3 1699
栀梦
栀梦 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

    You can crop images with CGImageCreateWithImageInRect:

    CGImageRef imageRef = CGImageCreateWithImageInRect([uncroppedImage CGImage], bounds);
    UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
    CGImageRelease(imageRef);
    

提交回复
热议问题