如何快速拍摄高质量的视频/照片?

maf*_*oso 1 camera ios swift

如何改善相机质量?我想拍摄全屏显示的图片/视频吗?如果我将会话预设设置为AVCaptureSessionPresetPhoto,则它是高质量和全屏模式,仅用于照片而非视频。我已经尝试了其他所有方法,但没有任何效果。当前,它看起来像这样:

在此处输入图片说明

编辑

为什么我的照片看起来像那样? 在此处输入图片说明

@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)
                }
            })
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

The*_*oup 5

使用 AVCaptureSessionPresetHigh

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

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

captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
Run Code Online (Sandbox Code Playgroud)