iOS - UIImageView - how to handle UIImage image orientation_ios

up vote18down votefavorite

12


Is it possible to setup UIImageView to handle image orientation? When I set the UIImageView to image with orientation RIGHT (it is photo from camera roll), the image is rotated to right, but I want to show it in proper orientation, as it was taken.

I know I can rotate image data but it is possible to do it more elegant?

Thank you

ios uiimageview uiimage orientation

shareimprove this question

asked Jan 18 '12 at 18:49

Martin Pilch

1,14021441





4 Answers

​active​​​​oldest​​​​votes​

up vote54down voteaccepted


If I understand, what you want to do is disregard the orientation of the UIImage? If so then you could do this:

UIImage *originalImage = [... whatever ...];

UIImage *imageToDisplay =
[UIImage imageWithCGImage:[originalImage CGImage]
scale:1.0
orientation: UIImageOrientationUp];

So you're creating a new UIImage with the same pixel data as the original (referenced via its CGImage property) but you're specifying an orientation that doesn't rotate the data.


shareimprove this answer

answered Jan 18 '12 at 19:05

Tommy

69.7k9107125






1



By the way, how can I actually rotate the image data? –  Eno Mar 8 '12 at 7:19


iOS - UIImageView - how to handle UIImage image orientation_sed_02

up vote20down vote


As Anomie suggests in their answer ​​here​​, this code will help to fix orientation: