检测iPhone相机方向
-
05-09-2019 - |
题
我这取决于我直接从相机获取图像中的回调,或从相机胶卷中选择它得到不一致的结果。
在UIImagePickerControllerDelegate
回调方法,所述UIImage.imageOrientation
出来作为UIImageOrientationRight
不管照片是如何作出。
而人像拍摄上来当读取它关闭相机胶卷,风景拍摄(打开左侧)出现UIImageOrientationUp
UIImageOrientationRight
。
如何能可靠地获得相机方向在这两种情况?
解决方案
我张贴这对苹果的论坛,并得到了解释:
“相机实际上是景观原生,所以你得到向上或向下,当你需要在景观的图片,向左或向右当你在人像照片(取决于你如何保持设备)。”
请参阅:
https://devforums.apple.com/message/301160#301160
感谢:
其他提示
我曾尝试imageOrientation属性的图片被服用后,这很有趣,因为我有方向值搞砸了。向上是左,下是右,左是向下和向右为Up,例如,如果我握着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];
您在自己的应用程序捕获图像之前。我即将去尝试这个测试自己,所以我希望它的作品!
不隶属于 StackOverflow