Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
[Android] Modify contrast using a ColorMatrix
ColorMatrixColorFilter setContrast(float contrast) {
float scale = contrast + 1.f;
float translate = (-.5f * scale + .5f) * 255.f;
float[] array = new float[] {
scale, 0, 0, 0, translate,
0, scale, 0, 0, translate,
0, 0, scale, 0, translate,
0, 0, 0, 1, 0};
ColorMatrix matrix = new ColorMatrix(array);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
return filter;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment