Modifier.ascii
Turn any element into ASCII.
Box(Modifier.ascii(charset = Charsets.Blocks, cell = 8.dp)) {
Image(painter = painterResource(Res.drawable.photo), contentDescription = null)
}
Modifier.ascii draws the element’s content into a graphics layer, samples it down to one tone per cell (and a color per cell when the color mode asks for it), maps the tones through the charset and draws the glyphs on top. Layout is unchanged.
| Parameter | Default | Meaning |
|---|---|---|
charset |
Charsets.Blocks |
Glyphs, see charsets. |
cell |
8.dp |
Width of one glyph cell. |
colorMode |
ColorMode.Theme |
See color modes. |
renderer |
AsciiRenderer.Auto |
See renderers. |
theme |
null |
Falls back to LocalKasciiTheme. |
For an image from a Bitmap use AsciiImage(bitmap), which samples tones and per-cell colors directly and is cheaper than capturing a layer.
Notes
- The content is re-sampled whenever the modifier redraws. Content that animates inside a child’s own graphics layer (
graphicsLayer { }, scrolling, video) does not trigger that, so passlive = trueto sample on every frame. It costs one sample per frame. - Semantics of the child are kept. The glyph layer adds nothing a screen reader would read twice.
- Sampling happens off the main thread. Until the first sample is ready the element draws plain paper.