我正在使用Swift的压缩库将图像压缩为NSData。
这是代码:
var imageCompressed:NSData
compression_encode_buffer( imageCompressed ,800000 , imageSelected , size , NULL , COMPRESSION_LZMA )
我收到以下错误消息:
无法将NSData类型的值转换为预期的参数类型UnsafeMutablePointer
最佳答案
我认为您想要的是这样的东西(imageSelected
和imageCompressed
被假定为Swift 3 Data对象):
imageSelected.withUnsafeBytes {(fromBytes: UnsafePointer<UInt8>) -> Void in
imageCompressed.withUnsafeMutableBytes {(toBytes: UnsafeMutablePointer<UInt8>) -> Void in
compression_encode_buffer(toBytes, toSize, fromBytes, fromSize, nil, COMPRESSION_LZMA)
}
}