我试图找出哪种方法能更好地捕捉JPEG
AVFoundatation - >的 PhotoCaptureDelegate
我可以使用:
photoSettings = AVCapturePhotoSettings(format: [ kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA) ])
或
photoSettings = AVCapturePhotoSettings(format: [AVVideoCodecKey : AVVideoCodecJPEG, AVVideoCompressionPropertiesKey : [AVVideoQualityKey : 1.0]] as [String : Any])
我注意到 AVVideoCodecJPEG ,我可以使用压缩质量;但是,如果我在 PhotoCaptureDelegate 中执行任何TIFF转换或 CMSampleBuffer 中的其他任务,我就无法使用。
是的,如果我想以新的方式保存到JPEG(猜测最有效的方式,我必须使用 AVVideoCodecJPEG 来做:
func capture(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhotoSampleBuffer photoSampleBuffer: CMSampleBuffer?, previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?) {
self.jpegPhotoData = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: photoSampleBuffer, previewPhotoSampleBuffer: previewPhotoSampleBuffer)
}
哪个更好用?