android为图片去色,返回灰度图片

就是大家喜闻乐见的图片去色,返回黑白的图片,具体的方法就是为bitmap添加colorFilter,废话不多说了,上代码:

 public static Bitmap getGreyImage(Bitmap old) {   
            int width, height;   
            height = old.getHeight();   
            width = old.getWidth();       
            Bitmap new= Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);   
            Canvas c = new Canvas(old);   
            Paint paint = new Paint();   
            ColorMatrix cm = new ColorMatrix();   
            cm.setSaturation(0);   
            ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);   
            paint.setColorFilter(f);   
            c.drawBitmap(new, 0, 0, paint);   
            return new;   
        }   

 

你可能感兴趣的:(android,灰度图)