UIImagePickerController:检查返回的图像是横向还是纵向? [英] UIImagePickerController: Check if returned image is in landscape or portrait?

查看:130
本文介绍了UIImagePickerController:检查返回的图像是横向还是纵向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,UIImagePickerController不支持横向方向.但是,在应用程序的一部分中,必须将来自控制器的图像识别为纵向或横向格式至关重要.

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.

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

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.

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

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?

推荐答案

如果您需要修复它,我用它来检查并修复取向.

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

这篇关于UIImagePickerController:检查返回的图像是横向还是纵向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆