is there any library that convert imagebitmap to p...
# multiplatform
j
is there any library that convert imagebitmap to png of bytearray?
j
yeah, but now I need to actually convert the imageBitmap from Compose to byteArray, that is all about loading from an actually bitmap
a
My bad, may be you will get more specific answer on the #CJLTWPH7S channel
j
thanks for your help bro
m
Give this a try:
Copy code
expect fun ImageBitmap.encodeToPngBytes(quality: Int = 100): ByteArray?

// Android
actual fun ImageBitmap.encodeToPngBytes(quality: Int): ByteArray? {
    ByteArrayOutputStream().use { bytes ->
        this.asAndroidBitmap().compress(Bitmap.CompressFormat.PNG, quality, bytes)
        return bytes.toByteArray()
    }
}

// On all other platforms
actual fun ImageBitmap.encodeToPngBytes(quality: Int): ByteArray? {
    return Image.makeFromBitmap(this.asSkiaBitmap()).encodeToData(org.jetbrains.skia.EncodedImageFormat.PNG, quality)?.bytes
}
187 Views