if I take a photo with the iPhone camera, I see that photo is 90 degree rotated. For instance if device orientation is UIDeviceOrientationPortrait the UIImage orientation is UIImageOrientationRight. How can I rotate the UIIMage so that if I post it on a website or Facebook, the photo is correctly orientated?
Asked
Active
Viewed 368 times
2
-
There is a similar post on this over [here](http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-image-orientation-after-upload). – Alan Apr 15 '12 at 19:03
-
There's a solution [here](http://stackoverflow.com/questions/20204495/mfmailcomposeviewcontroller-image-orientation) that also includes a lengthy explanation about what's actually going on. – Gallymon Nov 29 '13 at 04:34
1 Answers
0
I'm using this function in a UIImage category:
- (UIImage *)resizedImageWithContentMode:(UIViewContentMode)contentMode
bounds:(CGSize)bounds
interpolationQuality:(CGInterpolationQuality)quality {
CGFloat horizontalRatio = bounds.width / self.size.width;
CGFloat verticalRatio = bounds.height / self.size.height;
CGFloat ratio;
switch (contentMode) {
case UIViewContentModeScaleAspectFill:
ratio = MAX(horizontalRatio, verticalRatio);
break;
case UIViewContentModeScaleAspectFit:
ratio = MIN(horizontalRatio, verticalRatio);
break;
default:
[NSException raise:NSInvalidArgumentException format:@"Unsupported content mode: %d", contentMode];
}
CGSize newSize = CGSizeMake(self.size.width * ratio, self.size.height * ratio);
return [self resizedImage:newSize interpolationQuality:quality];
}
then just call:
UIImage *myCameraRollImage = ..//image received from camera roll
UIImage *mFixedRotationImage = [myCameraRollImage resizedImageWithContentMode:UIViewContentModeScaleAspectFit bounds:CGSizeMake(width, height) interpolationQuality:kCGInterpolationHigh];
Hope that helps!

Guntis Treulands
- 4,764
- 2
- 50
- 72