gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 06:05:36 28 4
gpt4 key购买 nike

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

enter image description here

EDIT

为什么我的照片看起来像那样? 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)
}
})
}
}
}

最佳答案

使用AVCaptureSessionPresetHigh

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

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

captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;

关于ios - 如何快速拍摄高质量的视频/照片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38685851/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com