iPhone AVFoundation camera orientation

前端 未结 12 633
走了就别回头了
走了就别回头了 2020-12-02 09:46

I\'ve been tearing my hair out trying to get the AVFoundation camera to capture a picture in the correct orientation (i.e. the device orientation) but I can\'t get it to wor

12条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 10:47

    there are two things to notice

    a) as Brian King wrote - LandscapeRight and LandscapeLeft are swapped in the enumeration. see AVCamCaptureManager example:

    // AVCapture and UIDevice have opposite meanings for landscape left and right (AVCapture orientation is the same as UIInterfaceOrientation)
    else if (deviceOrientation == UIDeviceOrientationLandscapeLeft)
        orientation = AVCaptureVideoOrientationLandscapeRight;
    else if (deviceOrientation == UIDeviceOrientationLandscapeRight)
        orientation = AVCaptureVideoOrientationLandscapeLeft;
    

    b) There are also UIDeviceOrientationFaceUp and UIDeviceOrientationFaceDown states, that if you try to set as the video orientation, your video will fail recording. Make sure you don't use them when calling [UIDevice currentDevice].orientation !

提交回复
热议问题