想要固定方向,但 UIImage 自动调整 [英] Want fixed orientation, but the UIImage autoratate

查看:28
本文介绍了想要固定方向,但 UIImage 自动调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 iOS 设计中的 UIImage 方向感到困惑.我只是使用故事板将我的 iPhone 拍摄的图像加载到 UIImageView 中,并期望它在模拟器中显示的完全相同.但是,它会旋转.(我选择内容模式为aspect fit)

I am confused about the UIImage orientation in my iOS design. I simply load an image taken by my iPhone into UIImageView using storyboard and expect it would be shown exactly the same in the simulator. However, it rotates. (I choose the content mode to be aspect fit)

我尝试使用从互联网下载的其他图像,它们都可以正常工作,但其中一张是相机拍摄的.

I try with other images downloaded from the internet all of them works fine but the one was taken by the camera.

有人知道为什么会这样吗?

Anyone have any idea why this happens?

我尝试打印我的示例中的 imageOrientation 属性.它显示 0,这是 .up 的默认值.

I try to print out imageOrientation property my example. It shows 0 which is the default value of .up.

图片似乎没有旋转,但在故事板和模拟器中看起来不同.

It seems the picture has not been rotated but it looks different in storyboard and simulator.

示例如下:

推荐答案

UIImage 有一个属性 imageOrientation,它指示 UIImageView 和其他 UIImage 消费者旋转原始图像数据.这个标志很有可能被保存到上传的 jpeg 图像中的默认数据中,但是您用来查看它的程序不尊重该标志.从 UIImage Picker Controller 获取图像时尝试更改方向.

A UIImage has a property imageOrientation, which instructs the UIImageView and other UIImage consumers to rotate the raw image data. There's a good chance that this flag is being saved to the default data in the uploaded jpeg image, but the program you use to view it is not honoring that flag. Try changing the orientation while fetching image from UIImage Picker Controller.

要旋转 UIImage 以在上传时正确显示,您可以使用类别.检查目标 C 中的 @Anomie's ans.如果你正在使用 Swift,您可以使用相同的逻辑为 UIImage 创建扩展.

To rotate the UIImage to display properly when uploaded, you can use a category. Check @Anomie's ans in Objective C. If you are using Swift you can create your extension for UIImage using same logic.

这篇关于想要固定方向,但 UIImage 自动调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆