Home > Tutorials > Image Processing – Brightness over Image

Image Processing – Brightness over Image

The concept of brightness is rather simple, increasing/decreasing value of each R, G, B channel  together.

+ By increasing: image results brighter.

+ By decreasing: image results darker.

This is the ogirinal one:

Original Image

Original Image

Applying several type of brightness:

Bright = 30

Bright = 30

Bright = 80

Bright = 80

Bright = -60

Bright = -60

From idea to implementation is very easy, piece of cake !!!

	public static Bitmap doBrightness(Bitmap src, int value) {
		// image size
		int width = src.getWidth();
		int height = src.getHeight();
		// create output bitmap
		Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
		// color information
		int A, R, G, B;
		int pixel;

		// scan through all pixels
		for(int x = 0; x < width; ++x) {
			for(int y = 0; y < height; ++y) {
				// get pixel color
				pixel = src.getPixel(x, y);
				A = Color.alpha(pixel);
				R = Color.red(pixel);
				G = Color.green(pixel);
				B = Color.blue(pixel);

				// increase/decrease each channel
				R += value;
				if(R > 255) { R = 255; }
				else if(R < 0) { R = 0; }

				G += value;
				if(G > 255) { G = 255; }
				else if(G < 0) { G = 0; }

				B += value;
				if(B > 255) { B = 255; }
				else if(B < 0) { B = 0; }

				// apply new pixel color to output bitmap
				bmOut.setPixel(x, y, Color.argb(A, R, G, B));

		// return final image
		return bmOut;

Hope you like it!

Pete Houston

  1. vali
    February 24, 2016 at 9:03 pm

    hi bro but it take to much time to process..

  2. sangharatna
    November 20, 2015 at 6:25 pm

    How can i do it using convolution matrix.

  3. September 1, 2015 at 10:42 pm

    hy guys can u help can u tel me where code paste in andriod which activity r used for pasting ode

  4. June 30, 2015 at 9:37 pm

    Hey bro, Thanks for this awesome tutorial. I am working on an app like the point brightness function in Snapspeed app, i.e., i want to apply brightness only to a user specified point.I am not getting any leads,Can u please help me out?

  5. July 20, 2014 at 12:50 pm

    hi it is really a wonderful tutorial but I wonder if you have a tutorial explains each code , and I have a question : Can we make an affects likes the instagram effects ?

  6. mel
    July 4, 2014 at 12:49 am

    Hey thanks for the code really helpful! iam trying to implement seam carving method for image scaling for an android app. sofar without success. you have any functions, algorithms doing that or any tips?
    thanks in advance!


  7. August 22, 2013 at 1:26 pm

    How to perform the same thing on Imageview Not on Bitmap?

  8. Ken
    December 12, 2012 at 11:08 am

    I have a problem like this, if we increase brightness by plus value and make the value of a,r,g,b over 255,the value of a,r,g,b will be : a = r = g= b = 255;when we decrease the brightness with the value = -20, the value of a,r,g,b will be same ,and make all of pixel of the image have the same color .
    My question is how can we decrease the level brightness when we have increased the value over 255 before.

  9. October 22, 2012 at 9:10 pm

    Thank you for the tutorial, but can you give the whole project of the application. It is too important for me, thank you! =)

  10. Rohit
    October 2, 2012 at 3:49 pm

    hey pete,

    i have just started learning android, so im a newbie

    i am trying to create an android application for image processing for my Project

    i came accross this blog entry :

    I am facing the following problem;

    i am unable to create a Bitmap object for my image stored as /res/drawable/pic_1.jpg

    i have tried using

    Bitmap myBitmap = BitmapFactory.decodeFile(“/res/drawable/pic_1.jpg”); and called the function;

    public static Bitmap doBrightness(myBitmap, int value) {………}

    but that didnt work;

    then i tried,

    Bitmap myBitmap = BitmapFactory.decodeFile(“/res/drawable/pic_2.jpg”);

    without calling the doBrightness() function.yet,it displays nothing in the imageview.

    so i guess BitmapFactory.decodeFile() is returning null.

    so what i wanted to know is,
    how is it possible to create Bitmap object for an image stored in /res/drawable?


    • October 2, 2012 at 4:06 pm

      It should be like this:
      Bitmap myBitmap = BitmapFactory.decodeFile(getResources(), R.drawable.pic_1);

      You cannot get items from “res” folder like that, it must be through whatever “R.drawable.*”
      or “R.layout.*” or “R.id.*” or blah blah..

      • Rohit
        October 2, 2012 at 4:09 pm

        it worked!!

        THANKS A TON!!!

  11. klexx
    April 10, 2012 at 2:23 am

    This is too slow when dealing with real time adjustment and multiple frames (animation).
    A much better way would be to take use of the ColorMatrix object when drawing the bitmap.

  12. April 9, 2012 at 2:59 pm

    i have try your code Pete…
    I try using a seekbar to change the value..
    but why its take s few times to process the image..

    but thanks to you pete,,,
    you mostly help my study…😀

    • Hardik
      February 19, 2013 at 7:33 pm

      Hi Pete thanks for this function as it is working properly but i am handling it on seekbar & the brightness effect is hapenning but very slow.so can you please help me out.thanks in advance.

      i am also having the slow processing done on seekbar.so if (adi)you have found the solution please do let me know how you have handled it.thanks anyways.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: