有这样一个图标
它画得像这样:
@Composable
private fun IconWithCircleBackground(
@DrawableRes res: Int,
modifier: Modifier = Modifier,
radius: Dp = 16.dp,
strokeColor: Color = ColorTokens.grey_10,
strokeWidth: Dp = 1.dp,
backgroundColor: Color = Color.Black,
backgroundAlpha: Float = 0.7f
) {
Box(modifier = modifier.size(radius)) {
Canvas(modifier = Modifier.size(radius)) {
drawCircle(
color = backgroundColor.copy(alpha = backgroundAlpha),
radius = radius.toPx() - strokeWidth.toPx() / 2
)
drawCircle(
color = strokeColor,
radius = radius.toPx(),
style = Stroke(width = strokeWidth.toPx())
)
}
Image(
painter = painterResource(id = res),
contentDescription = stringResource(id = ...)
)
}
}
即Canvas
在其上第一层绘制一个以黑色(+alpha)填充的圆圈作为背景,第二层绘制一条白线作为边框并且图标位于中心。
您需要制作第一层(黑色背景),以使其模糊。问题——这里如何应用模糊?