freddiewang
07/10/2021, 2:06 AMComposePath
directly? I would like to draw multiple paths with different transform matrices (including scale and rotation). but I am not sure how to draw it correctly in Composeromainguy
07/10/2021, 4:48 AMfreddiewang
07/10/2021, 6:20 AMfun sakura(): Path =
Path().apply {
moveTo(0f, 25f)
quadraticBezierTo(12.5f, 0f, 30f, 15f)
lineTo(20f, 20f)
lineTo(30f, 25f)
quadraticBezierTo(12.5f, 40f, 0f, 25f)
close()
}
@Composable
@Preview
fun SakuraPreview() {
Canvas(modifier = Modifier.fillMaxSize()) {
val path = sakura()
val rect = path.getBounds()
withTransform(transformBlock = {
val pivot = rect.center
rotate(45f, pivot = pivot)
scale(2f, 2f, pivot = pivot)
translate(100f, 100f)
}) {
drawPath(path, Color(0xFFFA9599))
// Draw the border for debug
drawRect(Color.Red, rect.topLeft, rect.size, style = Stroke(width = 1f))
}
}
}
The preview result look incorrect, I am not sure whether the pivot is incorrect or misuse the withTransform
freddiewang
07/10/2021, 6:45 AMPath
romainguy
07/10/2021, 5:01 PMfreddiewang
07/11/2021, 1:23 PM