2017-03-21 1 views
0

이것은 내 맞춤 카메라에서 캡처 사진에 사용했지만 실제로 사진을 캡처하는 코드이지만 사용자가 기기를 회전한다고 가정하면 (카메라는 여전히 아이폰 카메라처럼 세로로 유지됩니다) 사진을 찍으면 portrait.how에서 해당 사진을 원합니다. 그렇게?캡처 후 이미지의 방향을 바꾸는 방법은 무엇입니까?

 let stillImageOutput = self._getStillImageOutput() 

     if let videoConnection = stillImageOutput.connection(withMediaType: AVMediaTypeVideo) { 

    // videoConnection.videoOrientation = AVCaptureVideoOrientation.portrait 

     stillImageOutput.captureStillImageAsynchronously(from: videoConnection , completionHandler: { [weak self] sample, error in 

      if let error = error { 
       DispatchQueue.main.async(execute: { 
        self?._show(NSLocalizedString("Error", comment:""), message: error.localizedDescription) 
       }) 
       imageCompletion(nil,error as NSError?) 
       return 
      } 

      let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sample) 

      var capturedImage = UIImage(data: imageData!)[![This how photo showing if i capture by rotating Device][1]][1] 

This image i want in portrait

+0

가능한 중복 : // 유래 .com/questions/24965638/how-to-flip-uiimage-horizontally-with-swift) –

+0

아니요. 다른 질문입니다. –

+0

도움이 될 것입니다. Objective-C에 있지만 아이디어를 얻을 수 있습니다. http://stackoverflow.com/a/7932657/7005670 –

답변

2

videoConnection의 초기화 후 코드 아래에 추가하고 좋은 가고

switch UIDevice.current.orientation { 
       case .landscapeLeft: 
        videoConnection.videoOrientation = AVCaptureVideoOrientation.landscapeRight 
        break 
       case .landscapeRight: 
        videoConnection.videoOrientation = AVCaptureVideoOrientation.landscapeLeft 
        break 
       case .portrait: 
        videoConnection.videoOrientation = AVCaptureVideoOrientation.portrait 
        break 
       case .portraitUpsideDown: 
        videoConnection.videoOrientation = AVCaptureVideoOrientation.portraitUpsideDown 
        break 
       default: 
        videoConnection.videoOrientation = AVCaptureVideoOrientation.portrait 
        break 
       } 
[수평 스위프트에있는 UIImage 플립하는 방법?] (HTTP의
+0

고맙습니다. 너무 .. –

관련 문제