1
如何提高相機質量?我想採取全屏顯示的圖片/視頻?如果我將會話預設置爲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)
}
})
}
}
}
如果我想要全屏照片,則iPad無法正常工作 – mafioso
我剛剛在Air 2上測試過,它確實有效。你在用什麼? – TheValyreanGroup
我編輯了我的帖子,現在你看到了它的樣子 – mafioso