问题描述
是否可以设置 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?
推荐答案
如果我理解,你想要做的就是忽略 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 图像方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!