我得到一个表lensDistortionLookupTable
,它是AVCalibrationData的浮点数的NSData,并想将其转换为数组。那是什么
用Swift做正确的方法吗?
答案 0 :(得分:1)
Data
从withUnsafeBytes
中获取字节UnsafeBufferPointer
中的Float32
(根据文档)将其投射到常规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))
}