我试图找出哪个更好地捕捉JPEG
AVFoundation -> PhotoCaptureDelegate
我可以用:
photoSettings = AVCapturePhotoSettings(format: [ kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA) ])
或者
photoSettings = AVCapturePhotoSettings(format: [AVVideoCodecKey : AVVideoCodecJPEG, AVVideoCompressionPropertiesKey : [AVVideoQualityKey : 1.0]] as [String : Any])
我注意到使用AVVideoCodecJPEG,我可以使用压缩质量;但是,如果我正在PhotoCaptureDelegate中的CMSampleBuffer执行任何 TIFF 转换或其他任务,我将无法使用。
然而,如果我只想以新的方式保存到 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)
}
哪个更好用?