I try to covert ByteArray to UIImage and after that CIImage to get NSURL from CIImage and upload to Firebase Storage using the url, but I receive null value from the step of getting CIImage from UIImage, do someone encountered with this issue?
I tried to convert ByteArray to NSData and create UIImage from data, it succeed, but after that step I receive null value.
package app.data.imagePicker
import dev.gitlive.firebase.storage.File
import kotlinx.cinterop.BetaInteropApi
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.addressOf
import kotlinx.cinterop.convert
import kotlinx.cinterop.usePinned
import platform.CoreImage.CIImage
import platform.Foundation.NSData
import platform.Foundation.create
import platform.UIKit.UIImage
@OptIn(BetaInteropApi::class, ExperimentalForeignApi::class)
actual fun toFile(image: ByteArray): File? {
val ciImage = image.toNativeImage()
if (ciImage?.url() != null) {
return File(url = ciImage.url()!!)
} else {
return null
}
}
@OptIn(ExperimentalForeignApi::class, BetaInteropApi::class)
fun ByteArray.toNativeImage(): CIImage? = this.usePinned {
val nsData = NSData.create(bytes = it.addressOf(0), this.size.convert())
return CIImage.imageWithData(nsData)
}