Note that there are some explanatory texts on larger screens.

plurals
  1. POSave UIImage, Load it in Wrong Orientation
    text
    copied!<p>I am using the following code to save and load images that I pick from either the library or take using the camera:</p> <pre><code>//saving an image - (void)saveImage:(UIImage*)image:(NSString*)imageName { NSData *imageData = UIImagePNGRepresentation(image); //convert image into .png format. NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imageName]]; //add our image to the path [fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally save the path (image) NSLog(@"image saved"); } //loading an image - (UIImage*)loadImage:(NSString*)imageName { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imageName]]; return [UIImage imageWithContentsOfFile:fullPath]; } </code></pre> <p>This is how I set the picked image to be shown in my <code>UIImageView</code>:</p> <pre><code>imgView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; </code></pre> <p>However, when I pick and image and set it to be shown in my <code>UIImageView</code> it is fine, but when I load that image it often is the wrong orientation. Any ideas? Anyone experienced this or know how I could resolve this?</p> <p>Thanks.</p> <p>EDIT:</p> <p>So it seems, if you load a photo which was taken a photo in portrait upside-down, it loads in that orientation, if you take a photo in landscape left it loads in that orientation. Any ideas how to get around this? Whatever orientation they load it they always return as UIImageOrientationUp.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload