私は私が写真を撮るためにしようとしたカスタムカメラビューを持つスウィフト3を使用し、iPhone 7用スウィフト3 - 「AVFCapturePhotoOutput」を使用する方法 - 認識されていない生の形式BGRA
を開発しています。私が撮影した写真のUIImage
を表示しようとしていますが、私は次のエラーを取得する:
[AVCapturePhotoOutput DNGPhotoDataRepresentationForRawSampleBuffer:previewPhotoSampleBuffer:] Unrecognized raw format BGRA'
This answerはkCVPixelFormatType_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")
}
なぜBGRAを使用できませんか? –
あなたが何を求めているのか分かりません。それは本質的に私がこの質問をした理由です。 – noblerare
ああ、残念ですが、 'kCVPixelBufferPixelFormatTypeKey'をまったく設定しないとどうなりますか? –