0

I have a left-oriented image named "test.png" (like the 'R' image annotation of the doc of UIImageOrientationLeft), I first read it in with UIImage, and then create another UIImage with the image data of the first one and the orientation info, like this:

UIImage *image = [UIImage imageNamed:@"test"];
image = [UIImage imageWithCGImage:image.CGImage scale:1.f orientation:UIImageOrientationLeft];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
[imageView sizeToFit];

But the image displayed on imageView is upside-down. What's wrong?

an0
  • 17,191
  • 12
  • 86
  • 136

3 Answers3

1

I spent a great deal of time on this topic over the last few weeks. This might help you, but for a more in depth explanation, check this link out.

Between the two posts, there is information for why the images are rotated, as well as how to rotate them yourself.

Community
  • 1
  • 1
Boeckm
  • 3,264
  • 4
  • 36
  • 41
0

OK, it is a bit confusing. UIImageOrientationLeft corresponds to EXIF Orientation Tag 6 not 8. "Left" in UIImageOrientationLeft means the image needs to be rotated left to display properly, not the image is rotated left. So a left-oriented image loaded in a UIImage with UIImageOrientationLeft will be rotated left once more when displaying, resulting in an upside-down image.

an0
  • 17,191
  • 12
  • 86
  • 136
  • Correct, there's a good generic explanation of this photo behavior here: http://graphicssoft.about.com/od/digitalphotography/f/sideways-pictures.htm – Boeckm May 16 '12 at 17:21
0

That's because UIImage is supposed to automatically handle orientations and in this case, it was flipped twice. Note: one shouldn't rely on data provided by various image handling objects when it comes to RAW images.

TheBlack
  • 1,245
  • 1
  • 8
  • 12
  • So the problem is that the CGImage data read from UIImage may not be what I expect? If I read raw data into CGImage myself, then I can still use imageWithCGImage:scale:orientation: to create UIImage as I want, right? – an0 May 16 '11 at 23:30
  • You can use combinations of methods to load images in whatever way you like but be prepared for some problems with RAW images because since the last time I checked, there were still bugs with getting correct orientation for example: Nikon RAW photos. – TheBlack May 17 '11 at 09:36