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

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

@Auther: David
@email :[email protected]
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_第1张图片
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 :[email protected]
Learn from yesterday, live for today, hope for tomorrow.

你可能感兴趣的:(Utils)