I have an image and I want to draw dark rectangle over it with a transparent circle, so the result will be something like this:
我最终得到了这段代码:
Box(modifier = Modifier
.clip(RectangleShape)
.fillMaxSize()
.background(Color.Black)
.pointerInput(Unit) {
detectTransformGestures { centroid, pan, zoom, rotation ->
scale *= zoom
}
}) {
Image(
modifier = Modifier
.align(Alignment.Center)
.graphicsLayer(
scaleX = maxOf(.2f, minOf(5f, scale)),
scaleY = maxOf(.2f, minOf(5f, scale))
),
bitmap = bitmap.asImageBitmap(),
contentDescription = null
)
Canvas(modifier = Modifier.fillMaxSize(), onDraw = {
drawRect(Color.Black.copy(alpha = 0.8f))
drawCircle(
Color.Transparent,
style = Fill,
blendMode = BlendMode.Clear
)
})
}
但它似乎只是在图像顶部画了一个黑圆圈,而不是清除变暗的矩形......
如果您建议如何根据此圆坐标裁剪图像,这也会非常方便。
你需要使用clipPath在这种情况下。
Canvas(modifier = Modifier.fillMaxSize(), onDraw = {
val circlePath = Path().apply {
addOval(Rect(center, size.minDimension / 2))
}
clipPath(circlePath, clipOp = ClipOp.Difference) {
drawRect(SolidColor(Color.Black.copy(alpha = 0.8f)))
}
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)