本文转载至 http://stackoverflow.com/questions/8915630/ios-uiimageview-how-to-handle-uiimage-image-orientation
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
|
||
4 Answers
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:
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.
|
||||||||||||
|
up vote20down vote |
As Anomie suggests in their answer here, this code will help to fix orientation:
|
||||||||||||||||
|
up vote9down vote |
You can completely avoid manually doing the transforms and scaling yourself, as suggested by an0 in this answer here:
The documentation for the UIImage methods size and drawInRect explicitly states that they take into account orientation.
|
||
add a comment |
up vote4down vote |
here is a workable sample cod, considering the image orientation:
|