I am trying to add and icon from resource in Canvas
DrawScope
.
The nearest solution I found is drawImage()
, but it doesn't work for my case. Also I cannot use the normal Icon()
composable inside the DrawScope
. So is there any work around to display an icon inside canvas, similarly to the way we do it with composable:
import androidx.compose.material.Icon
Icon(Icons.Rounded.Menu, contentDescription = "Localized description")
Drawscope extension for abstract class Painter has size, alpha and colorFilter params. You can change these params. If you wish to change draw position of Icon, it' drawn top left (0,0) by default you can use translate function or other functions such as rotate or scale for further operations
val painter = rememberVectorPainter(Icons.Rounded.Menu)
Canvas(modifier = Modifier.fillMaxSize()) {
translate(left = 0f, top = 0f) {
with(painter) {
// draw(size = painter.intrinsicSize)
draw(
size = Size(40.dp.toPx(), 40.dp.toPx()),
alpha = 1f,
colorFilter = ColorFilter.tint(Color.Red)
)
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With