I\'m developing a Universal app and I\'m coding for iOS6.
I\'m using the imagePickerController to take a photo and then I am sending it as an attachment using MFMail
I think you can get the UIImage API to handle the rotation for you automatically, without needing to manually do the transforms.
The documentation for the UIImage methods size and drawInRect: both say they take the orientation into account, so I drawInRect the UIImage into a new context and grab the resultant (auto-rotated) image from there. Here's the code in a category:
@interface UIImage (Orientation)
- (UIImage*)imageAdjustedForOrientation;
@end
@implementation UIImage (Orientation)
- (UIImage*)imageAdjustedForOrientation
{
// The UIImage methods size and drawInRect take into account
// the value of its imageOrientation property
// so the rendered image is rotated as necessary.
UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
[self drawInRect:CGRectMake(0, 0, self.size.width, self.size.height)];
UIImage *orientedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return orientedImage;
}
@end
I just found this better answer by an0 which is virtually the same, but also includes the optimisation of not re-redrawing the image if the orientation is already correct.