检测 iPhone 相机方向

发布于 2024-07-22 01:20:41 字数 350 浏览 7 评论 0原文

根据我是直接从回调中的相机获取图像还是从相机胶卷中选择图像,我得到的结果不一致。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

帅哥哥的热头脑 2024-07-29 01:20:41

我将其发布到苹果论坛,并得到了解释:

“相机实际上是横向的,所以当你拍摄横向照片时你会向上或向下,而当你拍摄纵向照片时你会向左或向右(取决于你如何握住设备)。”

请参阅:

https://devforums.apple.com/message/301160#301160

谢谢:

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:

https://devforums.apple.com/message/301160#301160

Thanks:

https://devforums.apple.com/people/Rincewind

み青杉依旧 2024-07-29 01:20:41

我在拍摄照片后尝试了 imageOrientation 属性,这很有趣,因为我的方向值搞乱了。 上是左,下是右,左是下,右是上,例如,如果我将iPhone“向上”(正常位置),则imageOrientation是“UIImageOrientationRight”。

- (void)imagePickerController:(UIImagePickerController *)picker
  didFinishPickingImage:(UIImage *)image
      editingInfo:(NSDictionary *)editingInfo {
    switch (image.imageOrientation) {
      case UIImageOrientationUp: //Left
       break;
      case UIImageOrientationDown: //Right
       break;
      case UIImageOrientationLeft: //Down
       break;
      case UIImageOrientationRight: //Up
       break;
      default:
       break;
     }
}

目前我正在使用针对 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".

- (void)imagePickerController:(UIImagePickerController *)picker
  didFinishPickingImage:(UIImage *)image
      editingInfo:(NSDictionary *)editingInfo {
    switch (image.imageOrientation) {
      case UIImageOrientationUp: //Left
       break;
      case UIImageOrientationDown: //Right
       break;
      case UIImageOrientationLeft: //Down
       break;
      case UIImageOrientationRight: //Up
       break;
      default:
       break;
     }
}

Currently I am using 4.1 SDK GM (xcode_3.2.4_and_ios_sdk_4.1_gm_seed) targeting for iOS 3.1

梦在深巷 2024-07-29 01:20:41

我读过 某处 UIImagePickerController 没有打开监听硬件方向事件,因此您可能需要

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

在自己的应用程序中捕获图像之前调用。 我要去尝试自己测试一下,所以我希望它有效!

I have read somewhere that the UIImagePickerController doesn't turn on listening to hardware orientation events, so you may need to call

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

before you capture images in your own app. I'm about to go try testing this myself, so I hope it works!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文