简体   繁体   English

从原始表中提取值

[英]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 做到这一点的正确方法是什么?

  1. get the bytes from the Data with withUnsafeBytes使用withUnsafeBytesData获取字节
  2. use it to create a UnsafeBufferPointer of Float32 (according to the doc)用它来创建一个Float32UnsafeBufferPointer (根据文档)
  3. 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.

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