Daniel
05/28/2021, 10:08 PMIn addition to providing the ability to draw into a specified bounded area,However, the entire public api is just the propertyprovides a few high level mechanisms that consumers can use to configure how the content is drawn.Painter
intrinsicSize
and the extension function DrawScope.draw
. Confusingly draw
doesn't take the painter as an argument, so I'm not sure how it could work.
This is as far as I got:
val painter = painterResource(R.drawable.marker)
val size = painter.intrinsicSize
val image = ImageBitmap(size.width.roundToInt(), size.height.roundToInt())
val canvas = Canvas(image)
CanvasDrawScope().draw(LocalDensity.current, LocalLayoutDirection.current, canvas, size) {
}
Nader Jawad
05/28/2021, 10:25 PMdraw
method on Painter
is an extension method on DrawScope
so you would do the following in your CanvasDrawScope usage:
CanvasDrawScope().draw(LocalDensity.current, LocalLayoutDirection.current, canvas, size) {
with(painter) {
draw(size) // using default alpha and no colorfilter tinting
}
Daniel
05/28/2021, 11:06 PMNader Jawad
05/28/2021, 11:07 PMwith
to determine the proper scoping as well.