Ios Swift 3-在自定义相机视图上拍摄照片
我使用的是Swift 3,Xcode 8.2 我在这个主题上找到的很多教程似乎都在Swift 2中。我已经创建了一个自定义相机视图,我正在尝试从中捕获一张照片 我在下面设置了一个Ios Swift 3-在自定义相机视图上拍摄照片,ios,swift,swift3,avfoundation,Ios,Swift,Swift3,Avfoundation,我使用的是Swift 3,Xcode 8.2 我在这个主题上找到的很多教程似乎都在Swift 2中。我已经创建了一个自定义相机视图,我正在尝试从中捕获一张照片 我在下面设置了一个@IBAction函数。变量session\u output是AVCapturePhotoOutput: @IBAction func shutterButtonPressed() { session_output.capturePhoto(with: AVCapturePhotoSettings.init(fo
@IBAction
函数。变量session\u output
是AVCapturePhotoOutput
:
@IBAction func shutterButtonPressed() {
session_output.capturePhoto(with: AVCapturePhotoSettings.init(format: [AVVideoCodecKey : AVVideoCodecJPEG]), delegate: <#T##AVCapturePhotoCaptureDelegate#>)
}
@IBAction func shutterButtonPressed(){
会话_output.capturePhoto(带:AVCapturePhotoSettings.init(格式:[AVVideoCodecKey:AVVideoCodecJPEG]),委托:)
}
我不知道在delegate
字段中放什么,也不知道捕获后如何从缓冲区读取照片。在这种情况下,Swift 2和Swift 3之间的区别是如此明显,以至于我甚至无法通过我在遵循大多数Swift 2教程时已经相当成功地通过它
非常感谢您的帮助。将委托设置为self并使用此委托AVCapturePhotoCaptureDelegate 您可以从下面的代理获取捕获的图像
func capture(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhotoSampleBuffer photoSampleBuffer: CMSampleBuffer?, previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: NSError?) {
if let sampleBuffer = photoSampleBuffer, let previewBuffer = previewPhotoSampleBuffer, let dataImage = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: sampleBuffer, previewPhotoSampleBuffer: previewBuffer) {
print(image: UIImage(data: dataImage).size)
}
}
你试过了吗?是AVCapturePhotoCaptureDelegate。