我正在尝试使用Android Compose将彩色图像转换为黑白图像。
在视图系统中,我可以通过添加过滤器来将图像从彩色变为黑白,例如:
imageView.colorFilter = ColorMatrixColorFilter(ColorMatrix().apply { setSaturation(0f)})
如答案所示。
在Android Compose中,Image可组合功能已经具有颜色过滤器,但我找不到Compose包中等效的ColorMatrixColorFilter。
以下是我想要转换为灰度的图像代码:
Image(
asset = vectorResource(id = R.drawable.xxx),
modifier = Modifier.clip(RectangleShape).size(36.dp, 26.dp),
alpha = alpha,
alignment = Alignment.Center,
contentScale = ContentScale.Fit
)