You can use this:
public static Bitmap ConvertToBlackAndWhite(Bitmap sampleBitmap) {
ColorMatrix bwMatrix = new ColorMatrix();
bwMatrix.setSaturation(0);
final ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(
bwMatrix);
Bitmap rBitmap = sampleBitmap.copy(Bitmap.Config.ARGB_8888, true);
Paint paint = new Paint();
paint.setColorFilter(colorFilter);
Canvas myCanvas = new Canvas(rBitmap);
myCanvas.drawBitmap(rBitmap, 0, 0, paint);
return doBlackWhiteImage(rBitmap);
}
public static BlackWhiteImage doBlackWhiteImage(Bitmap myBitmap) {
int[] allpixels = new int[myBitmap.getHeight() * myBitmap.getWidth()];
myBitmap.getPixels(allpixels, 0, myBitmap.getWidth(), 0, 0,
myBitmap.getWidth(), myBitmap.getHeight());
for (int i = 0; i < myBitmap.getHeight() * myBitmap.getWidth(); i++) {
if (allpixels[i] == Color.BLACK)
// do something
else if (allpixels[i] == Color.TRANSPARENT)
// do something
else if (allpixels[i] == Color.WHITE)
// do something
else {
allpixels[i] = Color.WHITE;
}
}
myBitmap.setPixels(allpixels, 0, myBitmap.getWidth(), 0, 0,
myBitmap.getWidth(), myBitmap.getHeight());
return myBitmap;
}