Home > Tutorials > Image Processing – Snow Effect

Image Processing – Snow Effect


Well, still base on randomizing the pixel color, in contrast to the Black Filter, if set all pixels having R,G,B values to the max (0xFF) when they’re greater than threshold, then we have the Snow Effect.

Original Image

Original Image

Image w/ Snow Effect

Image w/ Snow Effect

I think it’s nice 🙂

	public static Bitmap applySnowEffect(Bitmap source) {
		// 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);
		// random object
		Random random = new Random();
		
		int R, G, B, index = 0, thresHold = 50;
		// 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;				
				// get color
				R = Color.red(pixels[index]);
				G = Color.green(pixels[index]);
				B = Color.blue(pixels[index]);
				// generate threshold
				thresHold = random.nextInt(COLOR_MAX);
				if(R > thresHold && G > thresHold && B > thresHold) {
					pixels[index] = Color.rgb(COLOR_MAX, COLOR_MAX, COLOR_MAX);
				}							
			}
		}
		// output bitmap				
		Bitmap bmOut = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
		bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
		return bmOut;
	}
Advertisements
Categories: Tutorials Tags: , , ,
  1. Anirudh Ganesh
    June 11, 2014 at 5:41 pm

    Hey is this an intensive process on a phone?As in does it take time? on my phone when I implemented it, it takes a good minute for it to load.

  2. January 10, 2014 at 2:47 am

    It’s awesome, love this effect.

  3. Rahul
    June 24, 2012 at 12:36 pm

    its just giving very low snow effect not on the full image

  4. pia
    June 4, 2012 at 6:14 pm

    color_max is not defined

    • pia
      June 4, 2012 at 7:06 pm

      ok i got it myself from other post.color_max=0xff

  5. Muhammad faisal
    November 30, 2011 at 5:04 am

    where you define colar_max ???

  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: