iOS - UIImageView - 如何处理 UIImage 图像方向

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)