UIImagePickerController: Check if returned image is in landscape or portrait? [duplicate]

人走茶凉 提交于 2019-12-11 11:44:38

问题


So, the UIImagePickerController does not support landscape orientation. However, there is a portion of application where it is essential that the image that comes from the controller is recognized to be either in a portrait or landscape format.

I can handle this so far when importing an image from my library using the UIImagePickerController. I just compare the UIImage's width and height. However, when I am capturing the image using the UIImagePickerController, this functionality won't work as is.

Is there some extra information that the UIImagePickerController can provide me to determine if it was snapped in a landscape mode? Is there a creative way in emulating this functionality for snapping photos using the UIImagePickerController?


回答1:


I used this to check and fix orientation if u need to fix it.

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");
}


来源:https://stackoverflow.com/questions/16009522/uiimagepickercontroller-check-if-returned-image-is-in-landscape-or-portrait

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!