1

所以, UIImagePickerController 不支持横向。但是,有一部分应用程序必须将来自控制器的图像识别为纵向或横向格式。

到目前为止,当使用 UIImagePickerController 从我的库中导入图像时,我可以处理这个问题。我只是比较 UIImage 的宽度和高度。但是,当我使用 UIImagePickerController 捕获图像时,此功能将无法正常工作。

UIImagePickerController 是否可以提供一些额外信息来确定它是否以横向模式拍摄?是否有一种创造性的方式来模拟使用 UIImagePickerController 拍摄照片的此功能?

4

1 回答 1

4

如果你需要修复它,我用它来检查和修复方向。

switch (image.imageOrientation) {
    case UIImageOrientationDown:
    case UIImageOrientationDownMirrored:
        transform = CGAffineTransformTranslate(transform, imageSize.width, imageSize.height);
        transform = CGAffineTransformRotate(transform, M_PI);
        break;

    case UIImageOrientationLeft:
    case UIImageOrientationLeftMirrored:
        transform = CGAffineTransformTranslate(transform, imageSize.width, 0);
        transform = CGAffineTransformRotate(transform, M_PI_2);
        break;

    case UIImageOrientationRight:
    case UIImageOrientationRightMirrored:
        transform = CGAffineTransformTranslate(transform, 0, imageSize.height);
        transform = CGAffineTransformRotate(transform, -M_PI_2);
        break;
    case UIImageOrientationUp:
    case UIImageOrientationUpMirrored:
        break;
}
/////////////// or u just do it in this way:
if (image.imageOrientation == UIImageOrientationUp) {
    NSLog(@"portrait");
} else if (image.imageOrientation == UIImageOrientationLeft || image.imageOrientation == UIImageOrientationRight) {
    NSLog(@"landscape");
}
于 2013-04-15T07:13:53.393 回答