Last active
May 27, 2024 16:19
-
-
Save riggaroo/ff15b46825995eafbc49d08215970d0f to your computer and use it in GitHub Desktop.
GraphicsLayer APIs - BlendMode per layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Preview | |
@Composable | |
private fun GraphicsLayerBlendModes() { | |
Box(modifier = Modifier | |
.fillMaxSize()){ | |
Image( | |
painter = painterResource(id = R.drawable.sunset), | |
contentDescription = null | |
) | |
val graphicsLayer2 = rememberGraphicsLayer() | |
Image( | |
painter = painterResource(id = R.drawable.dog), | |
modifier = Modifier | |
.blendLayer(graphicsLayer2, BlendMode.Lighten), | |
contentDescription = null | |
) | |
val graphicsLayer3 = rememberGraphicsLayer() | |
Image( | |
painter = painterResource(id = R.drawable.rainbow), | |
modifier = Modifier | |
.blendLayer(graphicsLayer3, BlendMode.Screen), | |
contentDescription = null | |
) | |
} | |
} | |
fun Modifier.blendLayer(layer: GraphicsLayer, blendMode: BlendMode): Modifier { | |
return this.drawWithContent { | |
layer.apply { | |
record { | |
[email protected]() | |
} | |
this.blendMode = blendMode | |
} | |
drawLayer(layer) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment