2016-07-31 128 views
1

如何提高相機質量?我想採取全屏顯示的圖片/視頻?如果我將會話預設置爲AVCaptureSessionPresetPhoto,那麼它的質量和全屏都很高,但僅適用於照片而不適用於視頻。我試過了其他一切,但沒有任何效果。 目前,它看起來像這樣:如何快速拍攝高質量的視頻/照片?

enter image description here

編輯

爲什麼看起來我的圖片這樣呢? enter image description here

@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) 
       } 
      }) 
     } 
    } 
} 

回答

4

使用AVCaptureSessionPresetHigh

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

然後,你需要設置你的全屏視頻的工作重心。

captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 
+0

如果我想要全屏照片,則iPad無法正常工作 – mafioso

+0

我剛剛在Air 2上測試過,它確實有效。你在用什麼? – TheValyreanGroup

+0

我編輯了我的帖子,現在你看到了它的樣子 – mafioso