Display a rotated image upright
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?
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.
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.
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.
精彩评论