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

标签 ios objective-c cocoa-touch uiimagepickercontroller landscape

这个问题在这里已经有了答案:





How to know if photo in Landscape or Portrait mode?

(2 个回答)


9年前关闭。




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

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

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

最佳答案

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

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

关于ios - UIImagePickerController:检查返回的图像是横向还是纵向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16009522/

相关文章:

ios - 如何从另一个类执行一个类的 collectionView 方法?

ios - 如何将字符串转换为 IP 地址?

iphone - 核心数据 : Checking for Null

iphone - Apple 在导航 Controller 内延迟加载图像,恢复为占位符图像

iphone - 有没有办法改变模态视图 Controller 外观的动画样式?

ios - 蓝牙 BLE 设备一连接就断开连接?

ios - 是否可以同时绑定(bind)两个观察者?

objective-c - 带有自定义后退导航按钮的自定义按钮栏

ios - 在 iOS 中渲染圆圈的最佳技术是什么?

objective-c - 子类化单例