Kazemihabib1996
05/06/2020, 5:33 PM@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▾
Kazemihabib1996
05/06/2020, 5:34 PMromainguy
05/06/2020, 5:39 PMsaveLayer()
at all in this exampleromainguy
05/06/2020, 5:40 PMromainguy
05/06/2020, 5:40 PMpaint.apply { blendMode = BlendMode.multiply }
romainguy
05/06/2020, 5:40 PMBlendMode
to anythingKazemihabib1996
05/06/2020, 5:43 PMKazemihabib1996
05/06/2020, 9:17 PM@Composable
fun donat(modifier: Modifier = Modifier) {
val icingPaint = remember {
Paint().apply {
asFrameworkPaint().pathEffect = ComposePathEffect(CornerPathEffect(40f), DiscretePathEffect(60f, 25f))
color = Color(0xFF53250F)
}
}
Canvas(modifier = modifier, onCanvas = {
val center = Offset(size.minDimension.value / 2, size.minDimension.value / 2)
val holePath = Path().apply {
addOval(Rect.fromCircle(center, size.minDimension.value / 6))
}
val icing = Path().apply {
addOval(Rect.fromCircle(center, size.minDimension.value / 2.5f))
op(this, holePath, operation = PathOperation.difference).also {
Log.d("OP RESULT", it.toString())
}
}
drawPath(icing, icingPaint)
})
}
but it doesn't work, but it works without asFrameworkPaint().pathEffect = ComposePathEffect(CornerPathEffect(40f), DiscretePathEffect(60f, 25f))
Kazemihabib1996
05/06/2020, 9:18 PMasFrameworkPaint().pathEffect = ComposePathEffect(CornerPathEffect(40f), DiscretePathEffect(60f, 25f))
Kazemihabib1996
05/06/2020, 9:20 PMnativeCanvas.clipPath(holePath.asAndroidPath(), Region.Op.DIFFERENCE)
with out removing that pathEffect.romainguy
05/06/2020, 9:21 PMKazemihabib1996
05/06/2020, 9:28 PMasFrameworkPaint().pathEffect = DiscretePathEffect(1f, 1f)
but didn't help.romainguy
05/07/2020, 7:51 PMromainguy
05/07/2020, 7:52 PMsaveLayer
basically creates a temporary render targetromainguy
05/07/2020, 7:52 PMromainguy
05/07/2020, 7:52 PMDstOut
) may only provide the desired results you want when starting from a transparent contentromainguy
05/07/2020, 7:52 PMromainguy
05/07/2020, 7:53 PMromainguy
05/07/2020, 7:53 PMromainguy
05/07/2020, 7:53 PMDstOut
does alpha composition, hence the saveLayer
romainguy
05/07/2020, 7:54 PMsaveLayer
calls have a cost (memory and rendering performance) so use them sparingly (or at least watch performance)romainguy
05/07/2020, 7:54 PMromainguy
05/07/2020, 7:54 PMromainguy
05/07/2020, 7:55 PMsaveLayer
for just one of the draw callsKazemihabib1996
05/07/2020, 8:03 PMBlendMode.kt
there are links to flutter docs and also the docs in that file is equal to to <https://api.flutter.dev/flutter/dart-ui/BlendMode-class.html>
that was reason for using flutter docs and samples for learning this stuff 😁romainguy
05/07/2020, 8:03 PMromainguy
05/07/2020, 8:04 PM