iOS - UIImageView - how to handle UIImage image orientation(iOS - UIImageView - 如何处理 UIImage 图像方向)
问题描述
是否可以设置 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 图像方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS - UIImageView - 如何处理 UIImage 图像方向


- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- URL编码Swift iOS 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- UITextView 内容插图 2022-01-01
- GPS状态的广播接收器? 2022-01-01