1

I'm developing an Android app using Jetpack Compose. Now, I'm trying to download images from Firebase Cloud Storage and show them on screen. As far as I searched how to do it, I need to convert ByteArray to Bitmap, but somehow I can't show images. Does anyone help me?

@Composable
  fun MyPage(navController: NavController, users: MutableList<User>) {
    val storage = Firebase.storage
    val usersImagesRef = storage.reference
    val userRef = usersImagesRef.child("userimage")
    val ONE_MEGABYTE: Long = 1024 * 1024
    userRef.getBytes(ONE_MEGABYTE).addOnSuccessListener {
        val bitmap = BitmapFactory.decodeByteArray(it, 0,  it.size)
    }
        Row() {
            if (bitmap != null) {
                Image(
                    painter = rememberImagePainter(bitmap),
                    contentScale = ContentScale.FillBounds,
                    contentDescription = null,
                    modifier = Modifier
                        .width(60.dp)
                        .height(60.dp)
                        .clip(CircleShape)
                )

Thank you.

Yuki
  • 225
  • 2
  • 7
  • 1
    Just curious, are you really required to get the image by decoding the stream?, I have a similar issue where I can't fetch images from `Firebase Storage ` but I'm not sure if it would solve your issue. I would assume your'e using `Coil`, you have to get the `downloadUrl` and you will supply it to your image fetcher https://stackoverflow.com/questions/73400464/coil-1-3-2-loading-image-from-firebase-not-working-no-fetcher-supports-gs – z.g.y Oct 10 '22 at 05:46
  • Can you check this stackoverflow [link1](https://stackoverflow.com/questions/11613594/android-how-to-convert-byte-array-to-bitmap) , [link2](https://stackoverflow.com/questions/35408941/how-to-convert-byte-array-into-bitmap-image) & [link3](https://stackoverflow.com/questions/7620401/how-to-convert-image-file-data-in-a-byte-array-to-a-bitmap) – Sathi Aiswarya Oct 10 '22 at 06:56
  • @SathiAiswarya Thanks, but I don't understand Java. I'm looking for code written in Kotlin. – Yuki Oct 10 '22 at 09:20
  • 1
    Have a look this [link1](https://www.android--code.com/2020/06/android-kotlin-bitmap-to-byte-array.html) & [link2](https://stackoverflow.com/a/67223773/18265638) – Sathi Aiswarya Oct 10 '22 at 13:01

0 Answers0