iOS - UIImageView - 如何处理UIImage图像方向 [英] iOS - UIImageView - how to handle UIImage image orientation
问题描述
是否可以设置 UIImageView 来处理图像方向?当我将 UIImageView 设置为方向 RIGHT (它是来自相机胶卷的照片)的图像时,图像会向右旋转,但我想以正确的方向显示它,因为它被拍摄了。
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?
谢谢
推荐答案
如果我明白,你想要什么do是无视UIImage的方向?如果是这样,那么你可以这样做:
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];
所以你要创建一个与原始像素数据相同的新UIImage(通过其CGImage引用)但是您指定的方向不会旋转数据。
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.
这篇关于iOS - UIImageView - 如何处理UIImage图像方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!