0

I have a Canvasin Jetpack Compose with a circle. Now I want to draw a Drawableover that circle right into the center. Thanks to the following answer StackOverflow answer I achieved the pure drawing onto the Canvas:

val vector = ImageVector.vectorResource(id = R.drawable.ic_launcher_foreground)
val painter = rememberVectorPainter(image = vector)
Canvas(modifier = Modifier.fillMaxSize()) {

    drawCircle(
        color = myColor.value,
        radius = MyRadius.toPx() - strokeWidth / 2,
        style = Fill
    )

    with(painter) {
        draw(painter.intrinsicSize)
    }
}

But now my drawable ist placed at the 0,0 position in the top left corner. How can I set the position of the VectorPainter to the center of the canvas? the draw()function unfortunately has no option for setting an Offset.

Vadim Kotov
  • 7,766
  • 8
  • 46
  • 61
J. Hegg
  • 661
  • 5
  • 19

0 Answers0