Created
April 9, 2011 04:49
-
-
Save SriramBms/911144 to your computer and use it in GitHub Desktop.
Code snippet to manipulate the brightness of an image in Android
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
// It's assumed this function is defined in a class extending 'ImageView' | |
void addEffectBrightness(){ | |
float brightness = mBrightnessValue; | |
mCm = new ColorMatrix(); | |
mCm.set(new float[] { 1, 0, 0, 0, brightness, | |
0, 1, 0, 0,brightness, | |
0, 0, 1, 0, brightness, | |
0, 0, 0, 1, 0 }); | |
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); | |
mPaint.setColorFilter(new ColorMatrixColorFilter(mCm)); | |
mCm = null; | |
} | |
redraw(mPaint); //the redraw func here should refresh the screen canvas | |
} | |
//---------------------------------------------------------------------------- | |
/*The brighness value can be changed and the effect viewed in realtime by | |
implementing android.widget.SeekBar.OnSeekBarChangeListener and refreshing(invalidate()) | |
the cavas each time its changed */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment