Convert bitmap to sepia in android

user430926 picture user430926 · Nov 10, 2010 · Viewed 9.2k times · Source

Is there any way to convert a Bitmap to sepia? I know to convert to grayScale is to set the setSaturation in ColorMatrix. But what about Sepia?

Answer

rude picture rude · Feb 5, 2012

If you have instance of image then you can use ColorMartix to draw it in Sepia. Let me describe way how you can do this using Drawable.

public static void setSepiaColorFilter(Drawable drawable) {
  if (drawable == null)
    return;

  final ColorMatrix matrixA = new ColorMatrix();
  // making image B&W
  matrixA.setSaturation(0);

  final ColorMatrix matrixB = new ColorMatrix();
  // applying scales for RGB color values
  matrixB.setScale(1f, .95f, .82f, 1.0f);
  matrixA.setConcat(matrixB, matrixA);

  final ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrixA);
  drawable.setColorFilter(filter);
}

Sample project was moved from Bitbucket to GitHub. Please check Release section to download APK binary to test without compiling.

enter image description here