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;   
        }   

 

 

posted @ 2012-06-11 17:13  ensai  阅读(209)  评论(0编辑  收藏  举报