DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Modify Contrast Using A ColorMatrix (on Android)

02.10.2010
| 6455 views |
  • submit to reddit
        
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;
}