2017-03-12 2 views
2

私は私が写真を撮るためにしようとしたカスタムカメラビューを持つスウィフト3を使用し、iPhone 7用スウィフト3 - 「AVFCapturePhotoOutput」を使用する方法 - 認識されていない生の形式BGRA

を開発しています。私が撮影した写真のUIImageを表示しようとしていますが、私は次のエラーを取得する:

[AVCapturePhotoOutput DNGPhotoDataRepresentationForRawSampleBuffer:previewPhotoSampleBuffer:] Unrecognized raw format BGRA'

This answerkCVPixelFormatType_24RGBが(何らかの理由で)iPhoneでサポートされていないことを私に伝えますので、私は何をするかわかりませんここからやってください。どんな助けでも大歓迎です。

func shutterButtonPressed() { 

    // apparently kCVPixelFormatType_24RGB is not supported for iPhone? 
    let photoPixelFormatType = kCVPixelFormatType_32BGRA 

    // using uncompressed format 
    let settings = AVCapturePhotoSettings(
        format: [kCVPixelBufferPixelFormatTypeKey as String : photoPixelFormatType]) 

    // thumbnail 
    let previewPixelType = settings.availablePreviewPhotoPixelFormatTypes.first! 
    let previewFormat = [kCVPixelBufferPixelFormatTypeKey as String: previewPixelType, 
         kCVPixelBufferWidthKey as String: 160, 
         kCVPixelBufferHeightKey as String: 160, 
         ] 
    settings.previewPhotoFormat = previewFormat 

    // get the actual video feed and take a photo from that feed 
    session_output.capturePhoto(with: settings, delegate: self) 


} 

func capture(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhotoSampleBuffer photoSampleBuffer: CMSampleBuffer?, previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?) { 

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

     // ERROR ON THIS LINE 
     if let sampleBuffer = photoSampleBuffer, let previewBuffer = previewPhotoSampleBuffer, let dataImage = AVCapturePhotoOutput.dngPhotoDataRepresentation(forRawSampleBuffer: sampleBuffer, previewPhotoSampleBuffer: previewBuffer) { 

      // this is the image that the user has taken! 
      let takenImage : UIImage = UIImage(data: dataImage)! 
     } else { 
      print("Error setting up photo capture") 
     } 
+0

なぜBGRAを使用できませんか? –

+0

あなたが何を求めているのか分かりません。それは本質的に私がこの質問をした理由です。 – noblerare

+0

ああ、残念ですが、 'kCVPixelBufferPixelFormatTypeKey'をまったく設定しないとどうなりますか? –

答えて

1

あなたは間違ったAVCapturePhotoOutputデリゲートメソッドを使用している可能性があります。試してみることができます

captureOutput:didFinishProcessingRawPhotoSampleBuffer:previewPhotoSampleBuffer:resolvedSettings:bracketSettings:error? 

設定にはAVCapturePhotoSettings(rawPixelFormatType:, processedFormat:)も使用する必要があります。

+0

フォーマット辞書を削除しますか? –

+0

私はあなたの答えのように2つの引数と引数なしで(AVCapturePhotoSettings)を試してみましたが、どちらも生の写真を処理するデリゲートと一緒に働いていませんでした.... – noblerare

+0

サンプルプロジェクトを作成してリンクできますか?ここに? –

関連する問題