Skip to content

Instantly share code, notes, and snippets.

@SriramBms
Created April 9, 2011 04:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SriramBms/911144 to your computer and use it in GitHub Desktop.
Save SriramBms/911144 to your computer and use it in GitHub Desktop.
Code snippet to manipulate the brightness of an image in Android
// 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