Aleksandar Ilic
01/27/2025, 7:15 PMandroidx.compose.ui.graphics.ImageBitmap
as PNG from the compose app. Any ideas how to do this? Or some links with examples? Ideally I want system’s share bottom sheet to pop up asking user what to do with the image, but I could also settle to some automatic export certain location where user can manually find it later. Thanks!Michael Paus
01/28/2025, 8:51 AMexpect fun ImageBitmap.encodeToBytes(quality: Int = 100): ByteArray?
Android:
actual fun ImageBitmap.encodeToBytes(quality: Int): ByteArray? {
ByteArrayOutputStream().use { bytes ->
this.asAndroidBitmap().compress(Bitmap.CompressFormat.PNG, quality, bytes)
return bytes.toByteArray()
}
}
All other platforms:
actual fun ImageBitmap.encodeToBytes(quality: Int): ByteArray? {
return Image.makeFromBitmap(this.asSkiaBitmap()).encodeToData(org.jetbrains.skia.EncodedImageFormat.PNG, quality)?.bytes
}
Aleksandar Ilic
01/28/2025, 11:55 AMMichael Paus
01/28/2025, 6:34 PMAleksandar Ilic
01/29/2025, 12:03 PMMichael Paus
01/29/2025, 2:09 PMMichael Paus
01/29/2025, 2:13 PMpdfbox = { module = "org.apache.pdfbox:pdfbox", version.ref = "pdfbox" }
pdfbox-android = { module = "com.tom-roush:pdfbox-android", version.ref = "pdfboxAndroid" }
These two variants a very similar and you can share much of your code but of course this is not multiplatform. For iOS one would have to look for something else.Aleksandar Ilic
01/30/2025, 6:54 PM