Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.ColorMatrix; import android.graphics.ColorMatrixColorFilter; import android.graphics.Paint; public class Main { /** * Method to remove colors in a Bitmap, creating a gray scale image. * * @param source The original Bitmap. * @return The gray scale Bitmap. */ public static Bitmap toGrayscale(Bitmap source) { Bitmap bmpGrayscale = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmpGrayscale); canvas.drawBitmap(source, 0, 0, getGrayScalePaint()); return bmpGrayscale; } private static Paint getGrayScalePaint() { Paint paint = new Paint(); paint.setAntiAlias(true); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); ColorMatrixColorFilter colorMatrixColorFilter = new ColorMatrixColorFilter(cm); paint.setColorFilter(colorMatrixColorFilter); return paint; } }