Created
November 7, 2011 07:10
-
-
Save erans/1344380 to your computer and use it in GitHub Desktop.
UIImage+Resize.m Fix for Rotation / Orientation on iOS 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UIImage *)resizedImage:(CGSize)newSize interpolationQuality:(CGInterpolationQuality)quality { | |
BOOL drawTransposed; | |
CGAffineTransform transform = CGAffineTransformIdentity; | |
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) { | |
// Apprently in iOS 5 the image is already correctly rotated, so we don't need to rotate it manually | |
drawTransposed = NO; | |
} else { | |
switch (self.imageOrientation) { | |
case UIImageOrientationLeft: | |
case UIImageOrientationLeftMirrored: | |
case UIImageOrientationRight: | |
case UIImageOrientationRightMirrored: | |
drawTransposed = YES; | |
break; | |
default: | |
drawTransposed = NO; | |
} | |
transform = [self transformForOrientation:newSize]; | |
} | |
return [self resizedImage:newSize | |
transform:transform | |
drawTransposed:drawTransposed | |
interpolationQuality:quality]; | |
} |
Have you switched out the imageWithCGImage:
method calls for imageWithCGImage:scale:orientation:
?
Thanks for your suggestion. The scale parameter wouldn't let me scale it to whatever I wanted (not just scaled). I'm quite sure that imageWithCGImage:scale:orientation: does a similar thing underneath.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For better performance, make sure to store some global flag that you are running in iOS version >= 5.0 so that you would only check a boolean flag instead of casting a string to a float and checking its value.