I get a table lensDistortionLookupTable
which is a NSData of floats of from AVCalibrationData and want to cast it into an array. What's the right way to do it with Swift?
Data
with withUnsafeBytes
UnsafeBufferPointer
of Float32
(according to the doc) cast it to a regular 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)) }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.