내가 스위프트 3 사용하고 개발하고 - "AVFCapturePhotoOutput"를 사용하는 방법. 내가 찍은 사진의 UIImage
을 표시하기 위해 노력하고 있지만 다음과 같은 오류 얻을 :스위프트 3 - 아이폰 7.</p> <p>내가 사진을 찍으려고하는 사용자 정의 카메라 뷰를위한 인식 할 수없는 원시 형식 BGRA
[AVCapturePhotoOutput DNGPhotoDataRepresentationForRawSampleBuffer:previewPhotoSampleBuffer:] Unrecognized raw format BGRA'
This answer이 kCVPixelFormatType_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")
}
왜 BGRA를 사용할 수 없습니까? –
나는 당신이 무엇을 요구하고 있는지 확신하지 못합니다. 이것이 본질적으로 내가이 질문을 한 이유입니다. – noblerare
오 죄송합니다 -'kCVPixelBufferPixelFormatTypeKey'를 전혀 설정하지 않으면 어떻게 될까요? –