Showing posts with label blur. Show all posts
Showing posts with label blur. Show all posts

Sunday, 21 April 2013

Snow Image Effect for android



Please use below class and pass the bitmap to this function and get return bitmap with Snow effect.




public class NewSnowFilter {

      public static final int COLOR_MIN = 0x00;
      public static final int COLOR_MAX = 0xFF;

      public static Bitmap applySnowEffect(Bitmap bitmap) {
            // get image size
            int width = bitmap.getWidth();
            int height = bitmap.getHeight();
            int[] pixels = new int[width * height];
            // get pixel array from source
            bitmap.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;
      }

}




By: NovaRadix Technology.


Gray Scale Photo Effect for android


Please use below class and pass the bitmap to this function and get return bitmap with gray scale effect.


public class GrayFilter {
     
      //   satutarion --- 1.0 , 0.5 and 0
     
      public static Bitmap changeToGray(Bitmap bitmap) {
            return changeToGray(bitmap, 0);
      }
     
      public static Bitmap changeToGray(Bitmap bitmap,float sat) {
            int width, height;
            width = bitmap.getWidth();
            height = bitmap.getHeight();
                 
            Bitmap grayBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
            Canvas canvas = new Canvas(grayBitmap);
            Paint paint = new Paint();
            paint.setAntiAlias(true);
                 
            ColorMatrix colorMatrix = new ColorMatrix();
            colorMatrix.setSaturation(sat);
                 
            ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix);
                 
            paint.setColorFilter(filter);
            canvas.drawBitmap(bitmap, 0, 0, paint);
                 
            return grayBitmap;
      }
}


By: NovaRadix Technology.



Call web services easily

get source code from here, Download