Created
March 15, 2011 07:57
-
-
Save granoeste/870440 to your computer and use it in GitHub Desktop.
[Android] Modify contrast using a ColorMatrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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