2

In my app, user can make a profile pic by uploading it from phone or taking one from the phone. Everything works fine, and the user is able to do any of these operations smoothly and the profile pic looks great, at the time of setting it up. But, when the user starts the app again, I fetch the path of the image and try to show it. And it is shown, but it is, for some reason, rotated for 90 or 180 degrees!

enter image description here

So, once again, at the moment when the user takes or uploads a pic from the phone, it is not rotated strangely like this, only on the next app life cycle.

Here is some code:

-(void)setAvatar
{
NSMutableArray* imagePathArray = [[Model shared] loadDataForKey:@"avatar"];
NSString *imagePath = [imagePathArray objectAtIndex:0];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
if (image!=nil)
_avatar.image = image;
}
BlaShadow
  • 11,075
  • 7
  • 39
  • 60
SteBra
  • 4,188
  • 6
  • 37
  • 68
  • 1
    What you need can be found here:http://stackoverflow.com/questions/23769310/scaling-uiimage-with-a-uiiimagepickers-cgaffinetransform-and-saving-to-parse-sd/23817549#23817549 – Jack Jun 13 '14 at 14:56

1 Answers1

1

I suppose the problem is because of skipping embedded metadata information. When you use Media Library to get an image (?) it includes orientation transformation info. After that you start to UIImage, but this class truncates all image metadata. That's why you see your image rotated after you save and reload it.

Accessing Image Metadata in iOS

voromax
  • 3,369
  • 2
  • 30
  • 53