简体   繁体   中英

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. What's the right way to do it with Swift?

  1. get the bytes from the Data with withUnsafeBytes
  2. use it to create a UnsafeBufferPointer of Float32 (according to the doc)
  3. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM