Reputation: 355
I am developing an Image manipulation software in android.i want to change the brightness of an particular image.how it can be done in code?
Upvotes: 4
Views: 8913
Reputation: 161
I'm using something like this at the moment:
if (brighter)
{
darknessPaint.setColorFilter(new PorterDuffColorFilter(Color.argb(level, 255, 255, 255), Mode.SRC_OVER));
}
else
{
darknessPaint.setColorFilter(new PorterDuffColorFilter(Color.argb(level, 0, 0, 0), Mode.SRC_ATOP));
}
darknessCanvas.setBitmap(dst);
darknessCanvas.drawBitmap(src, 0, 0, darknessPaint);
Indeed you could use LightningColorFilter too or ColorMatrixColorFilter. If anyone has a better (and by that I mean faster, besides using JNI which I haven't tried yet) method please let me know.
Upvotes: 7
Reputation: 6104
You probably want to look at LightingColorFilter
and Drawable
, or if you want to perform the manipulation manually, look at Bitmap
- specifically getPixels
and setPixels
(or copyPixelsFromBuffer
and copyPixelsToBuffer
if you wish).
Upvotes: 3