How to convert byte array to ImageBitmap in Compos...
# compose-desktop
j
How to convert byte array to ImageBitmap in Compose for Desktop? I am using Image.makeFromEncoded(this).toComposeImageBitmap(), but i get error Failed to Image:makeFromEncoded
m
Assuming
this
is your ByteArray, your code is correct and works on compose desktop. But you have to make sure that
this
actually contains valid image data like, e.g., the raw bytes of a JPG or PNG image. Not every possible image format is supported. So what do your bytes contain?
t
If you want to show uncompressed bitmap array you can use
Copy code
val imageInfo = ImageInfo(targetWidth, targetHeight, ColorType.BGRA_8888, ColorAlphaType.OPAQUE)
Make sure ColorType is matching your raw data. And than you can create a bitmap with:
Copy code
Bitmap().also {
    it.allocPixels(imageInfo)
    it.installPixels(byteArray)
}