Hey guys I want to mask text with an Image in Comp...
# multiplatform
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
🙌 14
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 🙂