如何快速拍摄高质量的视频/照片?
问题描述:
如何提高相机质量?我想采取全屏显示的图片/视频?如果我将会话预设置为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)
}
})
}
}
}
答
使用AVCaptureSessionPresetHigh
然后,你需要设置你的全屏视频的工作重心。
captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
如果我想要全屏照片,则iPad无法正常工作 – mafioso
我刚刚在Air 2上测试过,它确实有效。你在用什么? – TheValyreanGroup
我编辑了我的帖子,现在你看到了它的样子 – mafioso