Martin Pilch Martin Pilch - 8 months ago 62
iOS Question

iOS - UIImageView - how to handle UIImage image orientation

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


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:[originalImage scale]
              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.