如何将CVPixelBufferGetBaseAddress调用转换为Swift? [英] How to convert CVPixelBufferGetBaseAddress call to Swift?

查看:123
本文介绍了如何将CVPixelBufferGetBaseAddress调用转换为Swift?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我是Swift中第一个这样做的人,但是在Swift中使用&/inout和uint8_t似乎在网络上什么都没有.有人可以翻译一下吗?这种关系是按位的吗?

Maybe I'm the first person doing this in Swift but there seems to be nothing on the net using &/inout together with uint8_t in Swift. Could someone translate this please? Is this relationship bitwise?

Objective-C

Objective-C

uint8_t *buf=(uint8_t *) CVPixelBufferGetBaseAddress(cvimgRef);

迅速尝试

let inout buf:uint8_t = SOMETHING HERE CVPixelBufferGetBaseAddress(cvimgRef)

推荐答案

CVPixelBufferGetBaseAddress()返回UnsafeMutablePointer<Void>, 可以通过

let buf = UnsafeMutablePointer<UInt8>(CVPixelBufferGetBaseAddress(pixelBuffer))

已更新Swift 3(Xcode 8),已检查Swift 5(Xcode 11):

if let baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer) {
    let buf = baseAddress.assumingMemoryBound(to: UInt8.self)
    // `buf` is `UnsafeMutablePointer<UInt8>`
} else {
    // `baseAddress` is `nil`
}

这篇关于如何将CVPixelBufferGetBaseAddress调用转换为Swift?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆