Created
January 11, 2019 10:57
-
-
Save dmpatel151282/5e90b4720c6fb579a3a3d2c3477011cb to your computer and use it in GitHub Desktop.
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
/** | |
* | |
* @param bmp input bitmap | |
* @param contrast 0..10 1 is default | |
* @param brightness -255..255 0 is default | |
* @return new bitmap | |
*/ | |
public static Bitmap changeBitmapContrastBrightness(Bitmap bmp, float contrast, float brightness) | |
{ | |
ColorMatrix cm = new ColorMatrix(new float[] | |
{ | |
contrast, 0, 0, 0, brightness, | |
0, contrast, 0, 0, brightness, | |
0, 0, contrast, 0, brightness, | |
0, 0, 0, 1, 0 | |
}); | |
Bitmap ret = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig()); | |
Canvas canvas = new Canvas(ret); | |
Paint paint = new Paint(); | |
paint.setColorFilter(new ColorMatrixColorFilter(cm)); | |
canvas.drawBitmap(bmp, 0, 0, paint); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment