Kazemihabib1996
05/07/2020, 7:50 PMdrawRect(rect, paint.apply { color = Color.Red })
saveLayer(Rect.fromLTWH(0f, 0f, size.width.value, size.height.value), Paint().apply { blendMode = BlendMode.dstOut })
drawRect( rect.shift(Offset(20f, 20f)), paint.apply { color = Color.Blue } )
restore()
This example with `BlendMode.dstOut`not works correctly just the blue rectangle becomes black I don't understand why this happens.
2)
drawRect(rect, paint.apply { color = Color.Red })
drawRect( rect.shift(Offset(20f, 20f)), paint.apply {
color = Color.Blue, blendMode = BlendMode.dstOut }
)
This one is without saveLayer and just by applying the blendMode to the paint
it works for multiply but doesn't work for dstOut and produced the same result like the previous one.
3)
But if I call`saveLayer` with default blendMode of Paint, before both drawings in the above example it works I don't even need to restore it.
saveLayer(Rect.fromLTWH(0f, 0f, size.width.value, size.height.value), paint = Paint())
drawRect(rect, paint.apply { color = Color.Red })
drawRect(
rect.shift(Offset(20f, 20f)),
paint.apply {
color = Color.Blue
blendMode = BlendMode.dstOut
}
)
I don't understand it, why this happens?
based on the docs
* Saves a copy of the current transform and clip on the save stack, and then
* creates a new group which subsequent calls will become a part of. When the
* save stack is later popped, the group will be flattened into a layer and
* have the given `paint`'s [Paint.colorFilter] and [Paint.blendMode]
* applied.
I think the saveLayer must be called between the first and second drawRect and then I should call the restore but here I should call it before both drawings and even I don't need to call restore.