John O'Reilly
01/14/2024, 6:01 PMImageBitmap
using androidx.compose.ui.graphics.toComposeImageBitmap
....this works on all platform except for Android for some reason? Any known reason why that wold be the case? The same compose code/dependencies are used on all platforms.romainguy
01/14/2024, 6:06 PMromainguy
01/14/2024, 6:07 PMtoComposeImageBitmap
being a core Compose APIAlexander Zhirkevich
01/14/2024, 6:07 PMorg.jetbrains.skia
classes, it would not compile for androidromainguy
01/14/2024, 6:09 PMJohn O'Reilly
01/14/2024, 6:09 PMJohn O'Reilly
01/14/2024, 6:09 PMAlexander Zhirkevich
01/14/2024, 6:09 PMJohn O'Reilly
01/14/2024, 6:10 PMAlexander Zhirkevich
01/14/2024, 6:15 PMJohn O'Reilly
01/14/2024, 6:16 PMval decodedBytes = Base64.Default.decode(imageData)
image = Image.makeFromEncoded(decodedBytes).toComposeImageBitmap()
...
Image(
painter = BitmapPainter(image),
....
)
John O'Reilly
01/14/2024, 6:26 PMBitmap.asComposeImageBitmap
John O'Reilly
01/14/2024, 6:26 PMAlexander Zhirkevich
01/14/2024, 6:27 PMJohn O'Reilly
01/14/2024, 6:34 PMMichael Paus
01/14/2024, 7:02 PMfun imageBitmapFromBytes(encodedImageData: ByteArray): ImageBitmap {
return Image.makeFromEncoded(encodedImageData).toComposeImageBitmap()
}
and this on Android where we don’t have Skia access.
fun imageBitmapFromBytes(encodedImageData: ByteArray): ImageBitmap {
return BitmapFactory.decodeByteArray(encodedImageData, 0, encodedImageData.size).asImageBitmap()
}
The ByteArray is assumed to contain the bytes of a PNG or JPEG image.