public void changeImageColor2(ImageView imageView, int color, Context context) {
if (isGrayScale) {
// 如果已经是灰度图,则恢复原色
imageView.clearColorFilter();
isGrayScale = false;
//Toast.makeText(context, "is grey", Toast.LENGTH_SHORT).show();
} else {
// 将图片设置为黑白色
ColorMatrix matrix = new ColorMatrix();
matrix.setSaturation(color); // 设置饱和度为0,即变为灰度图
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
imageView.setColorFilter(filter);
isGrayScale = true;
//}
}
}
更改饱和度,
最新推荐文章于 2024-08-31 19:34:21 发布
这篇文章描述了一个Java方法changeImageColor2,用于在ImageView中动态改变图片的颜色,当传入参数指定时将其转换为灰度模式,并提供了相应的状态管理。
2127

被折叠的 条评论
为什么被折叠?



