Skip to content

Commit

Permalink
Converted final export operation to iOS 10 graphics renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
TimOliver committed Apr 20, 2024
1 parent 4df91ec commit 75031ff
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Objective-C/TOCropViewController/Categories/UIImage+CropRotate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 75031ff

Please sign in to comment.