3

I trying to achieve water reflection effect on bitmap. As I saw some apps called water reflection. I know how to do the reflection of the image but the wave on the image is what making me confused on how it is done.

see this image for example

enter image description here

I did many apps on bitmap manipulation but this is quite hard to achieve. So any idea on where to start. Just an idea to start can be helpful.

Sandeep R
  • 2,284
  • 3
  • 25
  • 51
  • Have You got solution, i have same problem – Butani Vijay Oct 11 '14 at 10:00
  • Did you find any solution how to create frame to produce a gif file or mp4?I have same issue too.I can create a rippled bitmap but can not find any way to produce moving wave and create frames.May you help me? – R1349 Sep 17 '21 at 19:40
  • Butani I saw you are looking for this issue too , could you find any solution for it? – R1349 Sep 17 '21 at 19:41

4 Answers4

3

For any one needed, I tried some simple tricks to get as closer as water reflection effect. It is not great but it looks fine to me.

I used two methods

Bitmap reflection method (give bitmap as a parameter)

  public static Bitmap Reflection(Bitmap imageBitmap) {

           int width = imageBitmap.getWidth();
           int height = imageBitmap.getHeight();

           Matrix matrix = new Matrix();
           matrix.preScale(1, -1);

          Bitmap reflectionImage = Bitmap.createBitmap(imageBitmap, 0,
                   0, width, height , matrix, false);

          Bitmap newbit=Bitmap.createScaledBitmap(reflectionImage, reflectionImage.getWidth()/8, reflectionImage.getHeight()/8, true);

          Bitmap newbit1=Bitmap.createScaledBitmap(newbit, newbit.getWidth()*8, newbit.getHeight()*8, true);

          Bitmap scalednew=Bitmap.createScaledBitmap(newbit1, width, height-(height/4), true);

          Bitmap newscaledone=overlay(scalednew);

       reflectionImage=newscaledone;

           Bitmap reflectedBitmap = Bitmap.createBitmap(width,
                   (height + height), Config.ARGB_8888);

           Canvas canvas = new Canvas(reflectedBitmap);
           canvas.drawBitmap(imageBitmap, 0, 0, null);
           Paint defaultPaint = new Paint();
           canvas.drawRect(0, height, width, height, defaultPaint);

           canvas.drawBitmap(reflectionImage, 0, height , null);
           Paint paint = new Paint();

           paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
           canvas.drawRect(0, height, width, reflectedBitmap.getHeight()
                    , paint);
               return reflectedBitmap;

}

Bitmap overlay method. I am taking a wave bitmap with some opacity to overlay on the reflected image. So that it may look like water.

 Bitmap wavebitmap=BitmapFactory.decodeResource(getResources(), R.drawable.waves1);

private static Bitmap overlay( Bitmap bmp2) {
     Bitmap bmp1=WaterReflectionMainActivity.wavebitmap;

      Bitmap bmp1new =Bitmap.createScaledBitmap(bmp1, bmp2.getWidth(), bmp2.getHeight(), true);

        Bitmap bmOverlay = Bitmap.createBitmap(bmp1new.getWidth(), bmp1new.getHeight(), bmp1new.getConfig());
        Canvas canvas = new Canvas(bmOverlay);
        canvas.drawBitmap(bmp2, new Matrix(), null);
        canvas.drawBitmap(bmp1new, new Matrix(), null);
        return bmOverlay;
    }

Well this is my version of water effect, I know this looks shit. So if anyone still got some better effect please share your code . thank you

Sandeep R
  • 2,284
  • 3
  • 25
  • 51
2

Tutorial related to this: http://www.xaraxone.com/webxealot/workbook34/page_4.htm Also have a read at this question: Add water effect on bitmap android. Have a read at both of them, i hope you will get an idea from this

You may also want to look through these: 1, 2, 3

Community
  • 1
  • 1
Daksh Shah
  • 2,997
  • 6
  • 37
  • 71
  • But there is no water effect tutorial which points to android.But good link sources though. – Sandeep R Feb 12 '14 at 07:35
  • @sandeep doing through android should be similar i think, do you mind putting a tick to my answer? – Daksh Shah Feb 12 '14 at 07:36
  • Yeah, I will wait for some more closer answers and then mark the answer which helped me to achieve my goal here. I will surely upvote your answer as it has some good sources. – Sandeep R Feb 12 '14 at 07:40
2

This is just an idea but basically, what you need is to apply a deformation on the bottom part of the image, meaning that for each pixel on the bottom half, you compute a position to get it's color from the top picture.

Here's a pseudo code to give you a hint :

for (int x = 0;  x < width; x++) {

    for (int y = 0; y < img.height; y++) {

        // Compute a position on the original image
        // tweak the values heres to get the effect you want
        sourceX = x + (int) (cos(10000.0 / y) * 20); 
        sourceY = img.height - y - 1 +(int)( sin(y* 0.5) * 20); 

        // Maybe check the range of sourceX and source Y

        int color = img.getColor(sourceX, sourceY) 

        outptut.setColor(x, y + img.height, color); 
   }
}
XGouchet
  • 10,002
  • 10
  • 48
  • 83
  • I got a doubt. In the second last line -"img.get" . what are we trying to get here..? – Sandeep R Feb 12 '14 at 09:34
  • img is the original image you want to add a reflection to. The img.get is actually getting the color at the point sourceX, sourceY. output.set is actually output.setColor (i'll edit my answer accordingly) – XGouchet Feb 12 '14 at 10:00
  • I think there is something wrong with the code. I get the error on int color line. – Sandeep R Feb 12 '14 at 10:15
  • in android its img.getPixel instead of img.getcolor – Sandeep R Feb 12 '14 at 10:17
  • Yes, as I said, it's pesudo code as I only tested it in Processing (didn't have time to setup a full app test to modify an image) – XGouchet Feb 12 '14 at 10:33
1

you can achieve this by masking may this code will help you

http://www.seeques.com/22527681/how-can-do-this-effect-in-android-may-be-android-bitmap-masking-effect.html

EDIT

also see this for reference

http://code.google.com/p/android-ripple-demo/source/browse/#svn%2Ftrunk%2Fsrc%2Fcom%2Fkesalin%2FRippleDemo

https://github.com/esteewhy/whater

http://code.google.com/p/waterrippleeffect/source/browse/trunk/src/com/example/android/watereffect/WaterEffectView.java?r=3

android noise effect on bitmap

Community
  • 1
  • 1
Hardik
  • 17,179
  • 2
  • 35
  • 40