Jan
12/14/2022, 6:21 PMenighma
12/14/2022, 10:43 PMJan
12/14/2022, 11:39 PMenighma
12/15/2022, 12:48 AMczuckie
12/15/2022, 8:38 AMJan
12/15/2022, 10:26 AMMichael Paus
12/15/2022, 12:10 PMfun svgPainter (encodedData: ByteArray, density: Density) : Painter? {
if (encodedData.isEmpty()) return null
try {
return androidx.compose.ui.res.loadSvgPainter(ByteArrayInputStream(encodedData), density)
} catch (e: Exception) {
log.error(e) { "Could not load painter for encoded SVG data." }
return null
}
}
I have written a service class for my own purposes which can read SVG from a ByteArray on Android, Desktop and Native (iOS,…). The code above is a fragment from the Desktop implementation. If there is some interest I could also provide the full code.Jan
12/15/2022, 4:39 PMenighma
12/16/2022, 9:33 PMloadSvgPainter
in https://developer.android.com/reference/kotlin/androidx/compose/ui/res/package-summary
?Michael Paus
12/17/2022, 10:41 AMloadSvgPainter
exists only for the desktop version as far as I know. E.g., in order to also support iOS I copied the one from Desktop into my projects iOS source set and with some tiny modification it also works there then because the loader works directly with Skia. For Android I use some other code which makes use of an external library because Skia access is not available on Android.Michael Paus
12/17/2022, 10:55 AMfun loadSvgPainter(
encodedData: ByteArray,
density: Density
): Painter {
val data = Data.makeFromBytes(encodedData)
return SVGPainter(SVGDOM(data), density)
}
That’s all. I needed these methods because I have to read SVGs from a database and not from a file.enighma
12/22/2022, 1:40 AM