From 75031ffc5c85a724e07bae9826fd1a5a14af3af1 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Sat, 20 Apr 2024 13:37:43 +0900 Subject: [PATCH] Converted final export operation to iOS 10 graphics renderer --- .../Categories/UIImage+CropRotate.m | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Objective-C/TOCropViewController/Categories/UIImage+CropRotate.m b/Objective-C/TOCropViewController/Categories/UIImage+CropRotate.m index 55c4db27..b2cad97d 100644 --- a/Objective-C/TOCropViewController/Categories/UIImage+CropRotate.m +++ b/Objective-C/TOCropViewController/Categories/UIImage+CropRotate.m @@ -33,10 +33,13 @@ - (BOOL)hasAlpha - (UIImage *)croppedImageWithFrame:(CGRect)frame angle:(NSInteger)angle circularClip:(BOOL)circular { - UIImage *croppedImage = nil; - UIGraphicsBeginImageContextWithOptions(frame.size, !self.hasAlpha && !circular, self.scale); - { - CGContextRef context = UIGraphicsGetCurrentContext(); + UIGraphicsImageRendererFormat *format = [UIGraphicsImageRendererFormat new]; + format.opaque = !self.hasAlpha && !circular; + format.scale = self.scale; + + UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:frame.size format:format]; + UIImage *croppedImage = [renderer imageWithActions:^(UIGraphicsImageRendererContext *rendererContext) { + CGContextRef context = rendererContext.CGContext; // If we're capturing a circular image, set the clip mask first if (circular) { @@ -68,10 +71,7 @@ - (UIImage *)croppedImageWithFrame:(CGRect)frame angle:(NSInteger)angle circular // We do not need to worry about specifying the size here since we're already // constrained by the context image size [self drawAtPoint:CGPointZero]; - - croppedImage = UIGraphicsGetImageFromCurrentImageContext(); - } - UIGraphicsEndImageContext(); + }]; // Re-apply the retina scale we originally had return [UIImage imageWithCGImage:croppedImage.CGImage scale:self.scale orientation:UIImageOrientationUp];