Android 自定义饱和度 实现黑白imageview

# 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);

【Android 自定义饱和度 实现黑白imageview】Android 自定义饱和度 实现黑白imageview
文章图片

step 2:转换颜色饱和度,实现黑白效果:
ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0f); // 设置饱和度:0为纯黑白,饱和度为0;1为饱和度为100,即原图; ColorMatrixColorFilter grayColorFilter = new ColorMatrixColorFilter(cm); imageview.setColorFilter(grayColorFilter);


end

@Auther: David @email :david.forever.god@gmail.com Learn from yesterday, live for today, hope for tomorrow.

    推荐阅读