ajay
ajay

Reputation: 355

How to change brightness of an image in android?

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

Answers (2)

Mihai F
Mihai F

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

Dave
Dave

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

Related Questions