首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIImageOrientation到CIDetectorImageOrientation

UIImageOrientation到CIDetectorImageOrientation
EN

Stack Overflow用户
提问于 2013-02-26 09:38:12
回答 3查看 3.2K关注 0票数 4

使用CIDetector来检测图像中的人脸,你需要根据文档指定图像方向,这意味着它与UIImageOrientation不同。谷歌为我找到了下面的功能,我试了试,但发现它似乎不正确,或者我可能遗漏了其他东西,因为有时方向是关闭的。有人知道是怎么回事吗?似乎一张照片从iDevice导出,然后导入到另一个iDevice,方向信息就会丢失/更改,从而导致一些方向不匹配。

代码语言:javascript
复制
- (int) metadataOrientationForUIImageOrientation:(UIImageOrientation)orientation
{
    switch (orientation) {
        case UIImageOrientationUp: // the picture was taken with the home button is placed right
            return 1;
        case UIImageOrientationRight: // bottom (portrait)
            return 6;
        case UIImageOrientationDown: // left
            return 3;
        case UIImageOrientationLeft: // top
            return 8;
        default:
            return 1;
    }
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-03-25 02:46:24

为了涵盖它们,并且不使用幻数赋值( CGImagePropertyOrientation的原始值可能会在未来发生变化,但这不太可能……这仍然是一个很好的实践)您应该包含ImageIO框架并使用实际的常量:

代码语言:javascript
复制
#import <ImageIO/ImageIO.h>
- (CGImagePropertyOrientation)CGImagePropertyOrientation:(UIImageOrientation)orientation
{
    switch (orientation) {
        case UIImageOrientationUp:
            return kCGImagePropertyOrientationUp;
        case UIImageOrientationUpMirrored:
            return kCGImagePropertyOrientationUpMirrored;
        case UIImageOrientationDown:
            return kCGImagePropertyOrientationDown;
        case UIImageOrientationDownMirrored:
            return kCGImagePropertyOrientationDownMirrored;
        case UIImageOrientationLeftMirrored:
            return kCGImagePropertyOrientationLeftMirrored;
        case UIImageOrientationRight:
            return kCGImagePropertyOrientationRight;
        case UIImageOrientationRightMirrored:
            return kCGImagePropertyOrientationRightMirrored;
        case UIImageOrientationLeft:
            return kCGImagePropertyOrientationLeft;
    }
}
票数 5
EN

Stack Overflow用户

发布于 2018-05-26 20:41:06

在Swift 4中

代码语言:javascript
复制
func inferOrientation(image: UIImage) -> CGImagePropertyOrientation {
  switch image.imageOrientation {
  case .up:
    return CGImagePropertyOrientation.up
  case .upMirrored:
    return CGImagePropertyOrientation.upMirrored
  case .down:
    return CGImagePropertyOrientation.down
  case .downMirrored:
    return CGImagePropertyOrientation.downMirrored
  case .left:
    return CGImagePropertyOrientation.left
  case .leftMirrored:
    return CGImagePropertyOrientation.leftMirrored
  case .right:
    return CGImagePropertyOrientation.right
  case .rightMirrored:
    return CGImagePropertyOrientation.rightMirrored
  }
}
票数 1
EN

Stack Overflow用户

发布于 2017-09-18 13:08:49

Swift 4:

代码语言:javascript
复制
func convertImageOrientation(orientation: UIImageOrientation) -> CGImagePropertyOrientation  {
    let cgiOrientations : [ CGImagePropertyOrientation ] = [
        .up, .down, .left, .right, .upMirrored, .downMirrored, .leftMirrored, .rightMirrored
    ]

    return cgiOrientations[orientation.rawValue]
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15079864

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档