我想以黑色/白色显示彩色图像,如何在 android jetpack compose 中使用 colorFilter 来实现?
Image(
painter = painter, contentDescription = null,
modifier = Modifier
.fillMaxSize(),
contentScale = scale,
colorFilter = null
)
答案 0 :(得分:4)
我们可以通过使用 colorMatrix 轻松实现:
val matrix = ColorMatrix()
matrix.setToSaturation(0F)
Image(
painter = painter, contentDescription = null,
modifier = Modifier
.fillMaxSize(),
contentScale = scale,
colorFilter = ColorFilter.colorMatrix(matrix)
)