Skip to content

Instantly share code, notes, and snippets.

@riggaroo
Last active May 27, 2024 16:19
Show Gist options
  • Save riggaroo/ff15b46825995eafbc49d08215970d0f to your computer and use it in GitHub Desktop.
Save riggaroo/ff15b46825995eafbc49d08215970d0f to your computer and use it in GitHub Desktop.
GraphicsLayer APIs - BlendMode per layer
@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