PngExporter

Rasterizes a list of Elements to PNG bytes. The raster counterpart to SvgExporter: where SVG re-derives each element's geometry as markup, this exporter renders through the SDK's real Compose renderer (renderElement) into an offscreen ImageBitmap, so the output is pixel-identical to what the on-screen canvas draws — no separate drawing path to drift.

Fidelity notes:

  • Paths, shapes, images render at full fidelity headlessly. Images are decoded synchronously (the async on-screen cache is bypassed).

  • Text needs a TextMeasurer to lay out — pass one from a composable via rememberTextMeasurer() for real glyphs. When textMeasurer is null, text elements render as their placeholder wrap-box outline (matching the renderer's own no-measurer fallback). JSON remains the lossless format.

Functions

Link copied to clipboard
fun exportToPng(elements: List<Element>, scale: Float = 1.0f, padding: Float = 20.0f, background: Color? = null, maxDimension: Int = 4096, textMeasurer: TextMeasurer? = null): ByteArray?