【问题标题】:Detecting iPhone camera orientation检测 iPhone 相机方向
【发布时间】:2009-05-25 03:29:03
【问题描述】:

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

UIImagePickerControllerDelegate回调方法中,无论照片如何拍摄,UIImage.imageOrientation都会出现UIImageOrientationRight

当从相机胶卷上读取它时,会出现一张风景照(向左转)UIImageOrientationUp,而一张肖像照会出现UIImageOrientationRight

如何在这两种情况下可靠地获取相机方向?

【问题讨论】:

  • 我发现了这个有点相关的链接mohrt.blogspot.com/2009/05/camera-image-orientation.html 并且知道 scaleAndRotateImage 代码blog.logichigh.com/2008/06/05/uiimage-fix ...但都没有解释为什么我可能直接从从传入的图像中获取不正确的 imageOrientation 信息回调。
  • 我遇到了同样的问题。例如,当我将 iphone 置于直立位置时,imageOrientation 为 3(UIImageOrientationRight,90 度 CW),当它向左转时为 0(UIImageOrientationUp)(我相信应该是 UIImageOrientationRight)。你找到解决办法了吗?
  • 我还没有找到解决方案,但我一直想检查 OS 3.0 是否解决了这个问题。
  • 加我到那些受苦的人:devforums.apple.com/thread/69393?tstart=0
  • 同样值得注意的是,不同设备(iPod vs iPhone4)和操作系统版本4.0、4.1等的行为是不同的。在我们的应用程序上,我们必须对一堆组合进行特殊处理才能获得完整覆盖范围。

标签: iphone ios objective-c camera uiimage


【解决方案1】:

我把这个贴到苹果论坛上,得到了解释:

“相机实际上是横向原生的,所以当你在横向拍摄照片时你是向上或向下,当你在纵向拍摄照片时你是向左或向右(取决于你拿着设备的方式)。”

见:

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

谢谢:

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

【讨论】:

    【解决方案2】:

    我在拍照后尝试了 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) 目标

    【讨论】:

    • 仅仅破解这个转换,你有什么快乐吗?
    【解决方案3】:

    我已经读到somewhere UIImagePickerController 没有开启监听硬件方向事件,所以你可能需要调用

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    

    在您自己的应用中捕获图像之前。我将自己尝试测试这个,所以我希望它有效!

    【讨论】:

    • 其实你的意思的语法是:[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多