我是swift的新手,我想在(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection委托中调用函数CMCopyDictionaryOfAttachments
我的代码:
// MARK: Delegates
func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
// got an image
let pixelBuffer : CVPixelBufferRef = CMSampleBufferGetImageBuffer(sampleBuffer)
let attachments : CFDictionaryRef = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, CMAttachmentMode( kCMAttachmentMode_ShouldPropagate)) as CFDictionaryRef!
}这通过xcode :'CMSampleBuffer' is not identical to 'CMAttachmentBearer'得到了一个错误,那么我如何使用sampleBuffer作为目标,这段代码如果用objective-c编写就能正常工作
发布于 2015-01-04 00:57:49
我猜您代码中的主要问题是您传递的是CMSampleBuffer而不是CVPixelBufferRef。
下一个问题是CMCopyDictionaryOfAttachments返回一个需要使用takeRetainedValue()进行转换的非托管实例。
func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
// got an image
let pixelBuffer : CVPixelBufferRef = CMSampleBufferGetImageBuffer(sampleBuffer)
let attachments : [NSObject : AnyObject] = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, pixelBuffer, CMAttachmentMode( kCMAttachmentMode_ShouldPropagate)).takeRetainedValue()
}https://stackoverflow.com/questions/27755958
复制相似问题