2

In my app, I need to save an image. I need the image to always be saved as a portrait, even if the device is in landscape mode. I am checking to see if the device is in landscape mode and if it is, I would like to rotate my image before it's saved as a PNG. Can anyone help me figure this out?

-(void) saveImage {

        UIGraphicsBeginImageContext(self.view.bounds.size);
        [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

        if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
            //// need to rotate it here
        }

        NSData *data = UIImagePNGRepresentation (viewImage);    

        [data writeToFile:savePath atomically:YES];

}
Brodie
  • 3,526
  • 8
  • 42
  • 61
  • Did you ever figure this out? I'm asking essentially the same question here: http://stackoverflow.com/questions/20764623/rotate-newly-created-ios-image-90-degrees-prior-to-saving-as-png ...I'd love any help you could provide. :) – Clifton Labrum Dec 27 '13 at 22:07

1 Answers1

0

This thread may help you. It shows how to use the imageOrientation method of a UIImage in order to switch the orientation. Hope that Helps!

Community
  • 1
  • 1
msgambel
  • 7,320
  • 4
  • 46
  • 62
  • Good thought but no joy. The image itself has to be rotated. When the view first loads, it looks at the image and rotates it depending on the device orientation, I need it to always be saved as portrait for this to work correctly. I've tried rotating the imageView prior to saving but that wont work either – Brodie Sep 04 '11 at 13:42