gpt4 book ai didi

swift - 如何将 CVImageBuffer 转换为 Unmanaged

转载 作者:行者123 更新时间:2023-11-28 05:34:10 24 4
gpt4 key购买 nike

我在 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()

我该如何转换这个?

谢谢!

最佳答案

CMSampleBufferGetImageBuffer() 不采用非托管对象(不再是?——也许改变了在 Beta 版本之间)。你可以替换

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

简单地通过

var imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)

关于swift - 如何将 CVImageBuffer 转换为 Unmanaged<CVImageBuffer>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25633669/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com