2

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)
}
10
  • Can you add some code ? Commented May 16, 2024 at 9:51
  • 1
    Just added ios part of the code where the problem occures Commented May 16, 2024 at 10:15
  • val ciImage = image.toNativeImage() , here you get ciiimage as nil ? Commented May 16, 2024 at 10:47
  • 1
    i think you are creating CIIMage from nsdata. So, it is an object. You need to save this image in file system, like documents directory in iOS. then you cabn find the local url. Commented May 16, 2024 at 12:02
  • 1
    how can I do it? Commented May 16, 2024 at 13:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.