Lalit has the most practical answer. However, you wanted the resulting gray to be the average value of red, green, and blue and should have set up your matrix like this:
float oneThird = 1/3f; float[] mat = new float[]{ oneThird, oneThird, oneThird, 0, 0, oneThird, oneThird, oneThird, 0, 0, oneThird, oneThird, oneThird, 0, 0, 0, 0, 0, 1, 0,}; ColorMatrixColorFilter filter = new ColorMatrixColorFilter(mat); paint.setColorFilter(filter); c.drawBitmap(original, 0, 0, paint);
And finally, when I encountered the problem of converting an image to shades of gray earlier - the most visually pleasing result in all cases is achieved not by averaging, but by providing each color with a different weight depending on its perceptual brightness, I tend to use these values:
float[] mat = new float[]{ 0.3f, 0.59f, 0.11f, 0, 0, 0.3f, 0.59f, 0.11f, 0, 0, 0.3f, 0.59f, 0.11f, 0, 0, 0, 0, 0, 1, 0,};