Swift 4 Camera NSInvalidArgumentException

时间:2017-10-21 05:29:34

标签: swift camera

我的自定义相机在swift 3中运行但是当我更新它时,我试图改变它以使用现在有用的功能

之前的代码:

func photoOutput(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhoto photoSampleBuffer: CMSampleBuffer?, previewPhoto previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?) {

  if let unwrappedError = error {
      print(unwrappedError.localizedDescription)
  } else {

      if let sampleBuffer = photoSampleBuffer, let dataImage = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: sampleBuffer, previewPhotoSampleBuffer: previewPhotoSampleBuffer) {

        if let finalImage = UIImage(data: dataImage) {
         let newImage = finalImage.resizeImage(image: finalImage)
         let place = CGPoint(x: newImage.size.width / 2, y: newImage.size.height/2)
Make sure point is within the image
        let color = newImage.getPixelColor(pos: place)
        print(color)
       displayCapturedPhoto(capturedPhoto: finalImage)
    }
   }
  }
}

更改代码:(不会工作)

    private func photoOutput(_ output: AVCaptureOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
    if let imageData = photo.fileDataRepresentation() {
        if let finalImage = UIImage(data: imageData) {
        let newImage = finalImage.resizeImage(image: finalImage)
        let place = CGPoint(x: newImage.size.width / 2, y: newImage.size.height/2)
        let color = newImage.getPixelColor(pos: place)
        print(color)
        displayCapturedPhoto(capturedPhoto: finalImage)
    }
    }
}

我不断收到如下错误:

  

NSInvalidArgumentException',原因:' *** - [AVCapturePhotoOutput capturePhotoWithSettings:delegate:]如果在设置中指定了非零格式字典,则委托必须响应选择器captureOutput:didFinishProcessingPhoto:error :或者已弃用的captureOutput:didFinishProcessingPhotoSampleBuffer:previewPhotoSampleBuffer:resolvedSettings:bracketSettings:error:

有什么想法吗?

0 个答案:

没有答案