检测 iPhone 相机方向
根据我是直接从回调中的相机获取图像还是从相机胶卷中选择图像,我得到的结果不一致。
在 UIImagePickerControllerDelegate
回调方法中,无论如何拍摄照片,UIImage.imageOrientation
都会显示为 UIImageOrientationRight
。
当从相机胶卷中读取它时,会出现一张横向照片(向左转)UIImageOrientationUp
,而一张纵向照片则会出现UIImageOrientationRight
。
如何在这两种情况下可靠地获取相机方向?
I'm getting inconsistent results depending on whether I get the image directly from the camera in the callback or choosing it from the camera roll.
In the UIImagePickerControllerDelegate
callback method, the UIImage.imageOrientation
comes up as UIImageOrientationRight
no matter how the photo is taken.
When reading it off the Camera Roll, a landscape shot (turned left) comes up UIImageOrientationUp
while a portrait shot comes up UIImageOrientationRight
.
How can I reliably get the camera orientation in both situations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将其发布到苹果论坛,并得到了解释:
“相机实际上是横向的,所以当你拍摄横向照片时你会向上或向下,而当你拍摄纵向照片时你会向左或向右(取决于你如何握住设备)。”
请参阅:
谢谢:
https://devforums.apple.com/people/Rincewind
I posted this to the Apple forums, and got the explanation:
"The camera is actually landscape native, so you get up or down when you take a picture in landscape and left or right when you take a picture in portrait (depending on how you hold the device)."
See:
Thanks:
https://devforums.apple.com/people/Rincewind
我在拍摄照片后尝试了 imageOrientation 属性,这很有趣,因为我的方向值搞乱了。 上是左,下是右,左是下,右是上,例如,如果我将iPhone“向上”(正常位置),则imageOrientation是“UIImageOrientationRight”。
目前我正在使用针对 iOS 3.1 的 4.1 SDK GM (xcode_3.2.4_and_ios_sdk_4.1_gm_seed)
I have tried the imageOrientation property after the picture has been taken, it's funny because I have the orientation values messed up. Up is Left, Down is Right, Left is Down and Right is Up, for example, if I hold the iPhone "Up" (the normal position) then imageOrientation is "UIImageOrientationRight".
Currently I am using 4.1 SDK GM (xcode_3.2.4_and_ios_sdk_4.1_gm_seed) targeting for iOS 3.1
我读过 某处 UIImagePickerController 没有打开监听硬件方向事件,因此您可能需要
在自己的应用程序中捕获图像之前调用。 我要去尝试自己测试一下,所以我希望它有效!
I have read somewhere that the UIImagePickerController doesn't turn on listening to hardware orientation events, so you may need to call
before you capture images in your own app. I'm about to go try testing this myself, so I hope it works!