2016-08-02 1 views
2

カメラを風景モードに設定するにはどうすればよいですか?写真を撮るたびに、画像はポートレート画像として保存されます。デバイスがランドスケープモードになっているときは写真はきれいに見えますが、カメラのロールで見るとそれはまだポートレートモードです。
これは私のテイク写真機能である:事前にカメラをすぐに風景モードに設定する方法はありますか?

// take a photo 
@IBAction func takePhoto(sender: AnyObject) { 
    self.fullScreenView.hidden = false 
    self.recordButton.enabled = false 
    self.takephoto.enabled = false 
    self.recordButton.hidden = true 
    self.takephoto.hidden = true 

    session.startRunning() 

    // customize the quality level or bitrate of the output photo 
    session.sessionPreset = AVCaptureSessionPresetPhoto 

    // add the AVCaptureVideoPreviewLayer to the view and set the view in fullscreen 
    fullScreenView.frame = view.bounds 
    videoPreviewLayer.frame = fullScreenView.bounds 
    fullScreenView.layer.addSublayer(videoPreviewLayer) 

    // add action to fullScreenView 
    gestureFullScreenView = UITapGestureRecognizer(target: self, action: #selector(ViewController.takePhoto(_:))) 
    self.fullScreenView.addGestureRecognizer(gestureFullScreenView) 

    // add action to myView 
    gestureView = UITapGestureRecognizer(target: self, action: #selector(ViewController.setFrontpage(_:))) 
    self.view.addGestureRecognizer(gestureView) 

    if (preview == true) { 
     if let videoConnection = stillImageOutput!.connectionWithMediaType(AVMediaTypeVideo) { 
      // code for photo capture goes here... 

      stillImageOutput?.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: { (sampleBuffer, error) -> Void in 
       // process the image data (sampleBuffer) here to get an image file we can put in our view 

       if (sampleBuffer != nil) { 
        let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer) 
        let image = UIImage(data: imageData, scale: 1.0) 

        self.fullScreenView.hidden = true 
        self.fullScreenView.gestureRecognizers?.forEach(self.fullScreenView.removeGestureRecognizer) 
        self.session.stopRunning() 

        // save image to the library 
        UIImageWriteToSavedPhotosAlbum(image!, nil, nil, nil) 

        self.imageViewBackground = UIImageView(frame: self.view.bounds) 
        self.imageViewBackground.image = image 
        self.imageViewBackground.tag = self.key 

        self.view.addSubview(self.imageViewBackground) 
       } 
      }) 
     } 
    } 
    else { 
     preview = true 
    } 
} 

ありがとう!

EDIT

私のプレビューがそのように見え、それは大丈夫です:

http://img5.fotos-hochladen.net/uploads/bildschirmfotom4s7diaehy.png

が、最後に、それは以下のようになります。

http://img5.fotos-hochladen.net/uploads/bildschirmfoto3c2rlwtevf.png

答えて

0

Iこの関数whを使うあなたに役立つかもしれません:

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) { 
     super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator) 

     let orientation = UIDevice.currentDevice().orientation 

     if UIDeviceOrientationIsPortrait(orientation) || UIDeviceOrientationIsLandscape(orientation) { 
      if let videoOrientation = AVCaptureVideoOrientation(rawValue: orientation.rawValue) { 
       (captureView.layer as! AVCaptureVideoPreviewLayer).connection.videoOrientation = videoOrientation 
      } 
     } 
    } 
+0

captureViewとは何ですか? – mafioso

+0

そのAVCaptureVideoPreviewLayer、接続が含まれています – Daniel

+0

captureView.layerは機能しません – mafioso

0

videoConnectionオブジェクトのvideoOrientationを設定します。

例えば:

videoConnection.videoOrientation = AVCaptureVideoOrientation.LandscapeRight

チェックデバイスの向きと、これはあなたの問題を解決する肖像画や風景

希望の両方のために働くvideoOrientationを設定します。

関連する問題