Open kokoichi206 opened 1 year ago
@Composable
fun ImageCrop() {
Box(
modifier = Modifier
.fillMaxSize(),
) {
Image(
modifier = Modifier
.fillMaxSize(),
painter = painterResource(id = R.drawable.background),
contentDescription = "",
)
Canvas(
modifier = Modifier
.fillMaxSize(),
) {
val canvasWidth = size.width
val canvasHeight = size.height
with(drawContext.canvas.nativeCanvas) {
val checkPoint = saveLayer(null, null)
drawRect(
color = Color.DarkGray.copy(alpha = 0.8f),
size = Size(canvasWidth, canvasHeight)
)
drawCircle(
color = Color.Transparent,
center = Offset(x = canvasWidth / 2, y = canvasHeight / 2),
radius = size.minDimension * 0.4f,
blendMode = BlendMode.Clear,
)
restoreToCount(checkPoint)
}
}
}
}
Crop Image
Links
memo
alpha がいじられているもの(blendMode = Clear を含む)は、Layer がなんか特殊な扱いされるので、少し頑張る必要あるみたい?