UIImagePickerController:检查返回的图像是横向还是纵向?

时间:2013-04-15 07:09:26

标签: ios objective-c cocoa-touch uiimagepickercontroller landscape

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

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

是否有一些额外的信息,UIImagePickerController可以提供我来确定它是否以横向模式捕捉?有没有一种创造性的方法来模拟使用UIImagePickerController捕捉照片的这个功能?

1 个答案:

答案 0 :(得分: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");
}