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

前端 未结 3 1696
栀梦
栀梦 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:24

    Don't forget to add scale parameter otherwise you will get low resolution image

    CGImageRef imageRef = CGImageCreateWithImageInRect([uncroppedImage CGImage], CGRectMake(0, 0, 30, 120));
    [imageView setImage:[UIImage imageWithCGImage:imageRef scale:[[UIScreen mainScreen] scale] orientation:UIImageOrientationUp]];
    CGImageRelease(imageRef);
    

提交回复
热议问题