Showing posts with label scale. Show all posts
Showing posts with label scale. Show all posts

Sunday, 21 April 2013

Reflection Photo Effect for android



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



public class NewReflection {

      public static final Bitmap applyReflection(Bitmap bitmap) {
            // gap space between original and reflected
            final int reflectionGap = 4;
            // get image size
            int width = bitmap.getWidth();
            int height = bitmap.getHeight();

            // this will not scale but will flip on the Y axis
            Matrix matrix = new Matrix();
            matrix.preScale(1, -1);

            // create a Bitmap with the flip matrix applied to it.
            // we only want the bottom half of the image
            Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2,
                        width, height / 2, matrix, false);

            // create a new bitmap with same width but taller to fit reflection
            Bitmap bitmapWithReflection = Bitmap.createBitmap(width,
                        (height + height / 2), Config.ARGB_8888);

            // create a new Canvas with the bitmap that's big enough for
            // the image plus gap plus reflection
            Canvas canvas = new Canvas(bitmapWithReflection);
            // draw in the original image
            canvas.drawBitmap(bitmap, 0, 0, null);
            // draw in the gap
            Paint defaultPaint = new Paint();
            canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint);
            // draw in the reflection
            canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);

            // create a shader that is a linear gradient that covers the reflection
            Paint paint = new Paint();
            LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
                        bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff,
                        0x00ffffff, TileMode.CLAMP);
            // set the paint to use this shader (linear gradient)
            paint.setShader(shader);
            // set the Transfer mode to be porter duff and destination in
            paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
            // draw a rectangle using the paint with our linear gradient
            canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
                        + reflectionGap, paint);

            return bitmapWithReflection;
      }

}








By: NovaRadix Technology.



Photo Sketch Effect for android




Please use below class and pass the bitmap to this function and get return bitmap with Sketch effect.You can also customize the value and get the customization of sketch effect.


public class Sketch {
      //  type = 3(Negative), 4(Pencil Sketch), 5(Color Pencil Sketch)
      public static final Bitmap changeToSketch(Bitmap bitmap) {
         return changeToSketch(bitmap, 5,110);
      }    
     
      public static final Bitmap changeToSketch(Bitmap src,int type,int threshold) {
          int width = src.getWidth();
        int height = src.getHeight();
        Bitmap result = Bitmap.createBitmap(width, height, src.getConfig());

        int A, R, G, B;
        int sumR, sumG, sumB;
        int[][] pixels = new int[3][3];
        for(int y = 0; y < height - 2; ++y) {
            for(int x = 0; x < width - 2; ++x) {
           //      get pixel matrix
                      for(int i = 0; i < 3; ++i) {
                    for(int j = 0; j < 3; ++j) {
                        pixels[i][j] = src.getPixel(x + i, y + j);
                    }
                }
            // get alpha of center pixel
                A = Color.alpha(pixels[1][1]);
                // init color sum
                sumR = sumG = sumB = 0;
                sumR = (type*Color.red(pixels[1][1])) - Color.red(pixels[0][0]) - Color.red(pixels[0][2]) - Color.red(pixels[2][0]) - Color.red(pixels[2][2]);
                sumG = (type*Color.green(pixels[1][1])) - Color.green(pixels[0][0]) - Color.green(pixels[0][2]) - Color.green(pixels[2][0]) - Color.green(pixels[2][2]);
                sumB = (type*Color.blue(pixels[1][1])) - Color.blue(pixels[0][0]) - Color.blue(pixels[0][2]) - Color.blue(pixels[2][0]) - Color.blue(pixels[2][2]);
                // get final Red
                R = (int)(sumR  + threshold);
                if(R < 0) { R = 0; }
                else if(R > 255) { R = 255; }
                // get final Green
                G = (int)(sumG  + threshold);
                if(G < 0) { G = 0; }
                else if(G > 255) { G = 255; }
                // get final Blue
                B = (int)(sumB  + threshold);
                if(B < 0) { B = 0; }
                else if(B > 255) { B = 255; }

                result.setPixel(x + 1, y + 1, Color.argb(A, R, G, B));
            }
        }
        return result;
      }
             

}

By: NovaRadix Technology.





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