NsData to ByteArray
actual typealias ImageBytes = NSData
actual fun ImageBytes.toByteArray(): ByteArray = ByteArray([email protected]()).apply {
usePinned {
memcpy(it.addressOf(0), [email protected], [email protected])
}
}
ByteArray to NsData
actual fun ByteArray.toImageBytes(): ImageBytes? = memScoped {
val string = NSString.create(string = [email protected]())
return string.dataUsingEncoding(NSUTF8StringEncoding)
}
ByteArray to NsData different way
actual fun ByteArray.toImageBytes() : ImageBytes = memScoped {
NSData.create(bytes = allocArrayOf(this@toImageBytes),
length = [email protected]())
}