Skip to content

Commit 75031ff

Browse files
committed
Converted final export operation to iOS 10 graphics renderer
1 parent 4df91ec commit 75031ff

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Objective-C/TOCropViewController/Categories/UIImage+CropRotate.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ - (BOOL)hasAlpha
3333

3434
- (UIImage *)croppedImageWithFrame:(CGRect)frame angle:(NSInteger)angle circularClip:(BOOL)circular
3535
{
36-
UIImage *croppedImage = nil;
37-
UIGraphicsBeginImageContextWithOptions(frame.size, !self.hasAlpha && !circular, self.scale);
38-
{
39-
CGContextRef context = UIGraphicsGetCurrentContext();
36+
UIGraphicsImageRendererFormat *format = [UIGraphicsImageRendererFormat new];
37+
format.opaque = !self.hasAlpha && !circular;
38+
format.scale = self.scale;
39+
40+
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:frame.size format:format];
41+
UIImage *croppedImage = [renderer imageWithActions:^(UIGraphicsImageRendererContext *rendererContext) {
42+
CGContextRef context = rendererContext.CGContext;
4043

4144
// If we're capturing a circular image, set the clip mask first
4245
if (circular) {
@@ -68,10 +71,7 @@ - (UIImage *)croppedImageWithFrame:(CGRect)frame angle:(NSInteger)angle circular
6871
// We do not need to worry about specifying the size here since we're already
6972
// constrained by the context image size
7073
[self drawAtPoint:CGPointZero];
71-
72-
croppedImage = UIGraphicsGetImageFromCurrentImageContext();
73-
}
74-
UIGraphicsEndImageContext();
74+
}];
7575

7676
// Re-apply the retina scale we originally had
7777
return [UIImage imageWithCGImage:croppedImage.CGImage scale:self.scale orientation:UIImageOrientationUp];

0 commit comments

Comments
 (0)