How to use AVCapturePhotoOutput

前端 未结 6 1804
予麋鹿
予麋鹿 2020-11-27 02:39

I have been working on using a custom camera, and I recently upgraded to Xcode 8 beta along with Swift 3. I originally had this:

var stillImageOutput: AVCapt         


        
6条回答
  •  [愿得一人]
    2020-11-27 03:21

    The capture delegate function has been changed to photoOutput. Here's the updated function for Swift 4.

    func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photoSampleBuffer: CMSampleBuffer?, previewPhoto previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?) {            
            if let error = error {
                print(error.localizedDescription)
            }
    
            if let sampleBuffer = photoSampleBuffer, let previewBuffer = previewPhotoSampleBuffer, let dataImage = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: sampleBuffer, previewPhotoSampleBuffer: previewBuffer) {
                print("image: \(String(describing: UIImage(data: dataImage)?.size))") // Your Image
            }
    }
    

提交回复
热议问题