Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw ImageVector on Canvas jetpack compose

I am converting SVG to vector asset by importing it to android studio. How can I draw that vector to canvas with jetpack compose. The only option I see is drawImage, which only takes ImageBitmap. But this is a vector and not a bitmap, so is there a way to just draw ImageVector.

val logoVector: ImageVector = ImageVector.vectorResource(id = R.drawable.diasyst_logo)
like image 561
V.Rashkov Avatar asked Dec 22 '25 05:12

V.Rashkov


1 Answers

You can wrap your ImageVector into a VectorPainter, which is able to render to the standard compose Canvas.

val vector = ImageVector.vectorResource(id = R.drawable.ic_launcher_foreground)
val painter = rememberVectorPainter(image = vector)
Canvas(modifier = Modifier.fillMaxSize()) {
    with(painter) {
        draw(painter.intrinsicSize)
    }
}
like image 90
Adrian K Avatar answered Dec 24 '25 05:12

Adrian K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!