Help us understand the problem. What is going on with this article?

UIDeviceOrientationを基準にしたUIImageOrientationとAVCaptureVideoOrientationの向き対応

More than 5 years have passed since last update.

AvFoundationなんかで遊んでいる時にデバイスの向きとカメラの向きで頭がこんがらがります。
背面カメラはそのまま、前面カメラはミラー前提です。

UIImageOrientation

- (UIImageOrientation)currentImageOrientation {
    UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];

    // 背面カメラチェック
    BOOL IsBack = [[_activeVideoInput device] position] ==AVCaptureDevicePositionBack;

    switch (deviceOrientation) {
        case UIDeviceOrientationLandscapeLeft:
            return IsBack ?  UIImageOrientationUp:UIImageOrientationDownMirrored;
            break;
        case UIDeviceOrientationLandscapeRight:
            return IsBack? UIImageOrientationDown :UIImageOrientationUpMirrored;
            break;
        case UIDeviceOrientationPortrait:
            return IsBack ?  UIImageOrientationRight:UIImageOrientationLeftMirrored;
            break;
        case UIDeviceOrientationPortraitUpsideDown:
            return IsBack ? UIImageOrientationLeft : UIImageOrientationRightMirrored;
            break;
        default:
            return UIImageOrientationRight;
            break;
    }
}

AVCaptureVideoOrientation

- (AVCaptureVideoOrientation)currentVideoOrientation {
    UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];

    switch (deviceOrientation) {
        case UIDeviceOrientationLandscapeLeft:
            return AVCaptureVideoOrientationLandscapeRight;
            break;
        case UIDeviceOrientationLandscapeRight:
            return AVCaptureVideoOrientationLandscapeLeft;
            break;
        case UIDeviceOrientationPortrait:
            return AVCaptureVideoOrientationPortrait;
            break;
        case UIDeviceOrientationPortraitUpsideDown:
            return AVCaptureVideoOrientationPortraitUpsideDown;
            break;
        default:
            return AVCaptureVideoOrientationLandscapeRight;
            break;
    }
}

corocorococoro
100人中5人くらいが嬉しいC#,objective-cのニッチなTipsを投稿出来れば
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした