Hey guys I want to mask text with an Image in Compose Multiplatform like the Image below any way to...
s
Hey guys I want to mask text with an Image in Compose Multiplatform like the Image below any way to implement this?
a
Here is full solution : I had already worked on this
Copy code
val image = ImageBitmap.imageResource(id = R.drawable.download_demo) // your image

Text(
    text = "LION",
    fontSize = 100.sp,
    fontWeight = FontWeight.ExtraBold,
    letterSpacing = (-2).sp, // optional, tighter look
    modifier = Modifier
        // draw text offscreen so blend mode works correctly
        .graphicsLayer { compositingStrategy = CompositingStrategy.Offscreen }
        .drawWithCache {
            val dst = IntSize(size.width.roundToInt(), size.height.roundToInt())
            onDrawWithContent {
                // 1) draw the text (destination)
                drawContent()
                // 2) draw the image using SrcIn so it shows only where text exists
                drawImage(
                    image = image,
                    dstSize = dst,
                    blendMode = BlendMode.SrcIn
                )
            }
        }
)
πŸ™ŒπŸ½ 1
πŸŽ‰ 10
🦸 7
❀️ 6
πŸ™ŒπŸΎ 1
🦸🏾 1
πŸ™Œ 15
Output :
@Shivam Dhuria
s
that worked thanks a lot!
πŸ‘ 2
a
Very kind of you @Aniket Shinde to provide a full solution like that πŸ‘
πŸ‘ 1
a
Always happy to help πŸ™‚