2017-06-05 82 views
5

我正在開發相機應用程序。我正在爲10.x設備使用AVCapturePhotoOutput,對於10.x設備使用AVCaptureStillImageOutput。問題在拍攝照片時使用AVCapturePhotoOutput拍攝wtth閃光燈

我使用下面的拍攝設置,同時捕捉照片

let settings = AVCapturePhotoSettings() 

let previewPixelType = settings.availablePreviewPhotoPixelFormatTypes.first! 
     let previewFormat = [kCVPixelBufferPixelFormatTypeKey as String: previewPixelType, 
          kCVPixelBufferWidthKey as String: 1080, 
          kCVPixelBufferHeightKey as String: 1080, 
          ] 
settings.previewPhotoFormat = previewFormat 
settings.isHighResolutionPhotoEnabled = true 
settings.flashMode = .on 
settings.isAutoStillImageStabilizationEnabled = true 
self.captureOutputPhoto?.capturePhoto(with: settings, delegate: self) 

,當我嘗試使用上面設置

captureOutput:didFinishProcessingPhotoSampleBuffer:previewPhotoSampleBuffer:resolvedSettings:bracketSettings:error 

上述委託拍攝的照片會拋出錯誤第一次。我是AVCapturePhotoSettings的初學者。每次使用閃光模式拍攝成功的照片後都會出現問題。

+1

您是否可以複製並粘貼您收到的錯誤消息? – gwinyai

+0

我得到同樣的錯誤。錯誤代碼-16005錯誤descritption:操作無法完成。這個錯誤發生在每次成功捕獲圖像時閃光模式設置爲 – 2017-06-06 03:31:32

+0

@Dhaval是否想要使用另一個類來捕獲閃光燈圖像? –

回答

-1

Apple documentation

如果閃光燈模式 上 你可能不使圖像穩定。 (啓用跳火 isAutoStillImageStabilizationEnabled 設置優先。)

不知道,如果它應該拋出錯誤,但你可以嘗試刪除該字符串

settings.isAutoStillImageStabilizationEnabled = true 
+0

通過評論'settings.isAutoStillImageStabilizationEnabled = true'來檢查此行。仍然面臨同樣的問題。 –

-1

我正在使用此方法處理閃光燈設置。 AVCaptureDevice基本上是您正在使用的相機,並且AVCaptureFlashMode是您要使用的閃光模式。

func changeFlashSettings(device: AVCaptureDevice, mode: AVCaptureFlashMode) { 
    do { 
     try device.lockForConfiguration() 
     device.flashMode = mode 
     device.unlockForConfiguration() 
    } catch { 
     print("Change Flash Configuration Error: \(error)") 
    } 
} 

有了這個,你可以將閃光燈設置設定爲onoffauto。希望這可以幫助。

+0

此解決方案適用於低於ios 10.x的版本現在AVCaptureStillImageOutput已棄用 –

+0

儘管已棄用AVCaptureStillImageOutput,但此方法仍可用於iOS 10.x版本。在發佈答案之前,我已經在具有10.3.2的iOS版本的真實設備上測試了代碼。 – Ayazmon