[英]Extracting values from raw table
I get a table lensDistortionLookupTable
which is a NSData of floats of from AVCalibrationData and want to cast it into an array.我得到一个表
lensDistortionLookupTable
,它是来自AVCalibrationData的浮点数的 NSData 并希望将其转换为数组。 What's the right way to do it with Swift?用 Swift 做到这一点的正确方法是什么?
Data
with withUnsafeBytes
withUnsafeBytes
从Data
获取字节UnsafeBufferPointer
of Float32
(according to the doc)Float32
的UnsafeBufferPointer
(根据文档) cast it to a regular Array
将其转换为常规
Array
let float32size = MemoryLayout<Float32>.stride // should be 4, but do not hardcode let elementCount = data.count / float32Size let table: [Float32] = depthData.cameraCalibrationData!.lensDistortionLookupTable.withUnsafeBytes { return Array(UnsafeBufferPointer<Float32>(start: $0, count: elementCount)) }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.