NSData to [Uint8] in Swift

后端 未结 7 798
无人及你
无人及你 2020-12-04 17:24

I couldn\'t find a solution to this problem in Swift (all of them are Objective-C, and they deal with pointers which I don\'t think exist in Swift in the same form). Is ther

7条回答
  •  Happy的楠姐
    2020-12-04 18:01

    swift 4 and image data to a byte array.

     func getArrayOfBytesFromImage(imageData:Data) ->[UInt8]{
    
        let count = imageData.count / MemoryLayout.size
        var byteArray = [UInt8](repeating: 0, count: count)
        imageData.copyBytes(to: &byteArray, count:count)
        return byteArray
    
    }
    

提交回复
热议问题