如何在swift中拍出高质量的videos/photos?

How to take high quality videos/photos in swift?

如何提高相机质量?我想要全屏显示的 pic/vid 吗?如果我将会话预设设置为 AVCaptureSessionPresetPhoto,它是高质量和全屏的,但仅适用于照片而不适用于视频。我已经尝试了所有其他方法,但没有任何效果。 目前,它看起来像这样:

EDIT

为什么我的照片看起来像那样?

@IBAction func takePhoto(sender: AnyObject) {
    var imageViewBackground: UIImageView!
    self.fullScreenView.hidden = false
    self.recordButton.enabled = false
    self.takephoto.enabled = false
    self.recordButton.hidden = true
    self.takephoto.hidden = true

    session.startRunning()

    // add the AVCaptureVideoPreviewLayer to the view and sets 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 dataProvider = CGDataProviderCreateWithCFData(imageData)
                    let cgImageRef = CGImageCreateWithJPEGDataProvider(dataProvider, nil, true, CGColorRenderingIntent.RenderingIntentDefault)
                    let image = UIImage(CGImage: cgImageRef!, scale: 1.0, orientation: UIImageOrientation.Right)

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

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

                    imageViewBackground = UIImageView(frame: CGRectMake(0, 0, self.width, self.height))
                    imageViewBackground.image = image
                    imageViewBackground.tag = self.key

                    self.view.addSubview(imageViewBackground)
                }
            })
        }
    }
}

使用AVCaptureSessionPresetHigh

https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureSession_Class/index.html#//apple_ref/c/data/AVCaptureSessionPresetHigh

然后您需要设置视频重力才能全屏工作。

captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;