iPhone AVFoundation camera orientation

前端 未结 12 616
走了就别回头了
走了就别回头了 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:52

    In Swift you should do this:

        videoOutput = AVCaptureVideoDataOutput()
        videoOutput!.setSampleBufferDelegate(self, queue: dispatch_queue_create("sample buffer delegate", DISPATCH_QUEUE_SERIAL))
    
        if captureSession!.canAddOutput(self.videoOutput) {
            captureSession!.addOutput(self.videoOutput)
        }
    
        videoOutput!.connectionWithMediaType(AVMediaTypeVideo).videoOrientation = AVCaptureVideoOrientation.PortraitUpsideDown
    

    It works perfectly for me!

提交回复
热议问题