检测iPhone相机的方向
我得到了不一致的结果,这取决于我是从callback中的相机中直接获取图像,还是从相机胶卷中select它。
在UIImagePickerControllerDelegate
callback方法中,无论拍摄照片如何, UIImage.imageOrientation
都会显示为UIImageOrientationRight
。
当从相机胶卷上读取它时,拍摄的风景(左转)出现UIImageOrientationUp
而人像拍摄出现UIImageOrientationRight
。
如何在两种情况下可靠地获取相机的方向?
我把这个贴到苹果论坛上,得到了解释:
“相机实际上是风景本地的,所以当你拍摄照片的时候,当你拍摄照片时,你可以上下拍照,也可以在拍照时拍照(取决于你如何拿着照相机)。”
看到:
https://devforums.apple.com/message/301160#301160
谢谢:
我已经尝试了图片拍摄后的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; } }
目前我正在使用4.1 SDK GM(xcode_3.2.4_and_ios_sdk_4.1_gm_seed)针对iOS 3.1
我读过的地方是UIImagePickerController没有打开硬件方向事件,所以你可能需要调用
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
在您自己的应用程序中捕捉图像之前。 我即将去尝试自己testing这个,所以我希望它的作品!