2016-09-23 82 views

回答

4

視頻方面,它不是一個簡單的更換AVCaptureStillImageOutput ImageAsynchronously捕獲靜止。

檢查the reference of AVCapturePhotoOutput

特別是,你可能需要在概述閱讀本部分:

  • 捕獲通過將您的照片設置圖像對象的capturePhoto (with:delegate :)方法以及實現AVCapturePhotoCaptureDelegate協議的代理對象 。捕獲輸出的照片 然後調用您的代理以在捕獲過程中通知您重要的 事件。
  • 實際的代碼示例在蘋果的示例代碼中發現: AVCam-iOS

    CameraViewController.swift

    Digestively,你需要兩樣東西,的AVCapturePhotoSettings一個實例,並符合AVCapturePhotoCaptureDelegate一個實例。然後撥打capturePhoto(with:delegate:)方法AVCapturePhotoOutput

    let photoSettings = AVCapturePhotoSettings() 
    //setup `photoSettings` 
    //... 
    //create an instance conforming to `AVCapturePhotoCaptureDelegate` 
    let photoCaptureDelegate = PhotoCaptureDelegate(with: photoSettings,...) 
    //`AVCapturePhotoCaptureDelegate` can be a complex object, so in the sample code, implemented in a separate file as `PhotoCaptureDelegate`. 
    //You need to keep strong reference to the delegate instance while capturing in progress. 
    self.photoOutput.capturePhoto(with: photoSettings, delegate: photoCaptureDelegate) 
    

    示例代碼會有一些您可能不需要的外部功能。您可以通過刪除它們來簡化它。

    (你沒有指定語言的標籤,但上面的示例代碼包含的Objective-C版本)。

    隨着委託的這個方法,你可以獲取圖像,類似的方法也存在RAW或Live照片。

    func capture(AVCapturePhotoOutput, didFinishProcessingPhotoSampleBuffer: CMSampleBuffer?, previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?) 
    
    相關問題