Home > Tutorials > Image Processing – Shading Filter

Image Processing – Shading Filter


Shading Filter” is a technique that use AND operator for the current pixel color and a desired-shading color.

Original Image

Original Image

Image w/ Shading (Sky Blue)

Image w/ Shading (Sky Blue)

Image /w Shading (Lawn Green)

Image /w Shading (Lawn Green)

Image w/ Shading (Violet)

Image w/ Shading (Violet)

I love her in Violet

Here the implementation:

	public static Bitmap applyShadingFilter(Bitmap source, int shadingColor) {
		// get image size
		int width = source.getWidth();
		int height = source.getHeight();
		int[] pixels = new int[width * height];
		// get pixel array from source
		source.getPixels(pixels, 0, width, 0, 0, width, height);

		int index = 0;
		// iteration through pixels
		for(int y = 0; y < height; ++y) {
			for(int x = 0; x < width; ++x) {
				// get current index in 2D-matrix
				index = y * width + x;
				// AND
				pixels[index] &= shadingColor;
			}
		}
		// output bitmap
		Bitmap bmOut = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
		bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
		return bmOut;
	}

 

Cheers,
Pete Houston

Categories: Tutorials Tags: , , ,
  1. Jeet Jivrajani
    December 13, 2016 at 6:10 pm

    can anyone please send me the whole code for this tutorial?

  2. yogesh kulkarni
    May 21, 2014 at 6:44 pm
  3. Gaurav
    November 6, 2013 at 10:17 pm

    in android we can pass “android.graphics.Color.argb(255, red, green, blue)” as shadingColor

    where
    red 0-255
    green 0-255
    blue 0-255

  4. shiv
    August 11, 2012 at 5:50 pm

    please tell me value of shadingColor

  5. July 3, 2012 at 6:10 pm

    Can you please provide shading values for above effects?

    • shiv
      August 11, 2012 at 5:53 pm

      i found value!!! u can try with -15000

    • June 19, 2014 at 11:36 am

      try with Color.Green, or Color.Blue. you can find multiple colors in the Color class provided by android.graphics.

  6. Rahul
    June 24, 2012 at 2:09 pm

    the value is around -15000 but is gives greenish effect

  7. pia
    June 5, 2012 at 1:04 am

    plz tell the shading color’s value if possible….

  8. Muhammad faisal
    November 30, 2011 at 5:17 am

    what value of shading color u pass for violet shad ??

  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: