title: Converting color bitmap to grayscale image using only the blue channel using a colormatrix
body: <p>I need to grayscale a bitmap in Android using only the blue color channel.
  I managed to get rid of the green and red channels by using a colormatrix, but when I set the saturation of that matrix to 0 it is ignoring the previously made changes to the red and green channels.</p>
  
  <p>Is there a way to accomplish my task? Iterating through the whole pixel array is not an option as it is way too slow.</p>
  
  <p>I'm using this piece of code:</p>
  
  <pre><code>public Bitmap ConvertToGrayscale(Bitmap bitmap) {
      int height = super.getHeight();
      int width = super.getWidth();
  
      float[] arrayForColorMatrix = new float[] {0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0,
                                                 0, 0, 1, 0, 0,
                                                 0, 0, 0, 1, 0};
  
      Bitmap.Config config = bitmap.getConfig();
      Bitmap grayScaleBitmap = Bitmap.createBitmap(width, height, config);
  
      Canvas c = new Canvas(grayScaleBitmap);
      Paint paint = new Paint();
  
      ColorMatrix matrix = new ColorMatrix(arrayForColorMatrix);
      matrix.setSaturation(0);
  
      ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
      paint.setColorFilter(filter);
  
      c.drawBitmap(bitmap, 0, 0, paint);
  
      return grayScaleBitmap;
  }
  </code></pre>