2017-03-12 1 views
2

내가 스위프트 3 사용하고 개발하고 - "AVFCapturePhotoOutput"를 사용하는 방법. 내가 찍은 사진의 UIImage을 표시하기 위해 노력하고 있지만 다음과 같은 오류 얻을 :스위프트 3 - 아이폰 7.</p> <p>내가 사진을 찍으려고하는 사용자 정의 카메라 뷰를위한 인식 할 수없는 원시 형식 BGRA

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

This answerkCVPixelFormatType_24RGB은 (어떤 이유로) 아이폰에서 지원하지 않는 하더군요을 그래서 나도 몰라 무엇을 여기에서 해. 어떤 도움이라도 대단히 감사합니다.

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

답안에서와 같이 두 개의 인수를 사용하고 인수가없는 AVCapturePhotoSettings를 사용해 보았지만 둘 다 원시 사진을 처리하는 위임자와 함께 작업하지 않았습니다. – noblerare

+0

샘플 프로젝트를 만들고 링크 할 수 있습니까? 이리? –