如何将CVImageBuffer转换为Unmanaged <cvimagebuffer>?</cvimagebuffer>

时间:2014-09-02 22:56:49

标签: swift ios8 xcode6

我在Swift中有这个代码并得到一个错误:CVImageBuffer不能转换为Unmanaged

  func getTextureFromSampleBuffer(sampleBuffer: CMSampleBuffer!) -> GLuint {
    cleanupVideoTextures()
   var unmanagedImageBuffer: Unmanaged<CVImageBuffer> = CMSampleBufferGetImageBuffer(sampleBuffer)  // Here get the error
    var imageBuffer = unmanagedImageBuffer.takeUnretainedValue()
    var opaqueImageBuffer = unmanagedImageBuffer.toOpaque()

我该如何投这个?

谢谢!

1 个答案:

答案 0 :(得分:2)

CMSampleBufferGetImageBuffer()不会占用一个非托管对象(可能会改变它) 测试版之间)。你可以替换

var unmanagedImageBuffer: Unmanaged<CVImageBuffer> = CMSampleBufferGetImageBuffer(sampleBuffer)  // Here get the error
var imageBuffer = unmanagedImageBuffer.takeUnretainedValue()

简单地通过

var imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)