在机器人的黑白照片

时间:2011-03-18 08:00:51

标签: android

  

可能重复:
  how to force a photo into black and white

当我从移动相机拍照时,我想存储黑白照片。

1 个答案:

答案 0 :(得分:8)

这样的事情应该有效:

public Bitmap greyScaler(Bitmap b) {    
     Bitmap grayscaleBitmap = Bitmap.createBitmap(b.getWidth(),
            b.getHeight(), Bitmap.Config.RGB_565);
     Canvas c = new Canvas(grayscaleBitmap);
     Paint p = new Paint();
     ColorMatrix cm = new ColorMatrix();
     cm.setSaturation(0);
     ColorMatrixColorFilter filter = new ColorMatrixColorFilter(cm);
     p.setColorFilter(filter);
     c.drawBitmap(b, 0, 0, p);
     return grayscaleBitmap;
}