# Android 自定义饱和度 实现黑白imageview
@Auther: David
@email :david.forever.god@gmail.com
Learn from yesterday, live for today, hope for tomorrow.
start
step 1:得到Imageview,并附上图片:
Resources res = getResources();
Bitmap bmp= BitmapFactory.decodeResource(res, R.drawable.h1);
imageview.setImageBitmap(bmp);
step 2:转换颜色饱和度,实现黑白效果:
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0f); // 设置饱和度:0为纯黑白,饱和度为0;1为饱和度为100,即原图;
ColorMatrixColorFilter grayColorFilter = new ColorMatrixColorFilter(cm);
imageview.setColorFilter(grayColorFilter);
end
本文介绍如何使用Android通过调整饱和度实现ImageView中图片的黑白显示效果。步骤包括获取资源并加载图片到ImageView,然后通过ColorMatrix调整饱和度为0来达到完全的黑白效果。
516

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



