yeah, but now I need to actually convert the imageBitmap from Compose to byteArray, that is all about loading from an actually bitmap
a
alexandre mommers
10/17/2024, 3:07 PM
My bad, may be you will get more specific answer on the #CJLTWPH7S channel
j
juhaodong
10/17/2024, 3:08 PM
thanks for your help bro
m
Michael Paus
10/17/2024, 10:01 PM
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
}