Create a gist now

Instantly share code, notes, and snippets.

UIImage+Resize.m Fix for Rotation / Orientation on iOS 5
- (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];
}
@erans
Owner
erans commented Nov 7, 2011

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.

@tonyarnold

Have you switched out the imageWithCGImage: method calls for imageWithCGImage:scale:orientation:?

@erans
Owner
erans commented Feb 28, 2012

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