Created
November 11, 2025 11:30
-
-
Save Mikkareem/5454fa8ddce919372851b385909e87f8 to your computer and use it in GitHub Desktop.
Image Blending Effect using Jetpack Compose (CompositingStrategy & BlendMode)
This file contains hidden or 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
| @Composable | |
| private fun ImageBlendingEffect1Example() { | |
| Box( | |
| modifier = Modifier | |
| .fillMaxSize() | |
| .background(Color.Blue), | |
| contentAlignment = Alignment.Center | |
| ) { | |
| Image( | |
| painter = painterResource(R.drawable.background), | |
| contentDescription = null, | |
| contentScale = ContentScale.FillBounds, | |
| modifier = Modifier.fillMaxSize() | |
| ) | |
| var center = remember { mutableStateOf(Offset.Zero) } | |
| Box( | |
| Modifier | |
| .graphicsLayer(compositingStrategy = CompositingStrategy.Offscreen) | |
| .fillMaxSize() | |
| .pointerInput(Unit) { | |
| detectDragGestures { change, _ -> | |
| center.value = change.position | |
| } | |
| } | |
| .drawWithCache { | |
| onDrawWithContent { | |
| drawContent() | |
| // OR BlendMode.Clear | |
| val blendMode = BlendMode.Xor | |
| drawCircle( | |
| color = Color.White, | |
| blendMode = blendMode, | |
| radius = 100.dp.toPx(), | |
| center = center.value | |
| ) | |
| } | |
| } | |
| ) { | |
| Image( | |
| painter = painterResource(R.drawable.foreground), | |
| contentDescription = null, | |
| contentScale = ContentScale.FillBounds, | |
| modifier = Modifier.fillMaxSize() | |
| ) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment