I'm trying the saveLayer and blendMode (I'm using this for the first time I've never used that before even in the previous android UIToolkit). So I followed this tutorial that's originally written for flutter
https://stackoverflow.com/a/59650400/4146943
and I ended up with this code in jetpack compose
@Composable
fun testBlending2(modifier: Modifier = Modifier) {
val paint = remember { Paint() }
Canvas(modifier = modifier, onCanvas = {
save()
val rect = Rect(0f, 0f, 100f, 100f)
drawRect(rect, paint.apply { color = Color.Red })
saveLayer(Rect.fromLTWH(0f, 0f, size.width.value, size.height.value), paint.apply { BlendMode.multiply })
drawRect(
rect.shift(Offset(20f, 20f)),
paint.apply { color = Color.Blue }
)
restore()
restore()
})
}
It's supposed to be
but it just produces this image:
https://i.stack.imgur.com/q3In0.png▾
What am I doing wrong?