0

In my application,I want to combine two bitmaps for example a leaf and its shadow, in water.I am able to combine those bitmaps and make the combined bitmap freely fall from the top of the screen with some rotation in a live wallpaper.In my combined image the shadow is a little bit below the original leaf and left to it.If the combined image is rotating with some angle,the shadow also rotates with that angle.It seems to be like that the shadow is rotating like original image. But the shadow position should be always below the original image. But some times shadow is appearing on top of the original image while the combined image is falling with rotation because they are merged.I do not want this.I want the shadow always below the original image under any instance.How can i achieve this?Please help me.I am providing my code to combine the two bitmaps.

 public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
    Bitmap bmoverlay = null;
 bmoverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
    Canvas canvas = new Canvas(bmoverlay);
    canvas.drawBitmap(bmp1, null, new Rect(0, 0, canvas.getWidth() ,    canvas.getHeight()), null);
    canvas.drawBitmap(bmp2, 20, 20, null);
 return bmoverlay;
     }

Please suggest me how to do or any other method which does my requirement?Thanks in advance.

Itisme
  • 53
  • 6
  • where is that Bitmap used for? – pskink Jun 24 '14 at 07:32
  • it is used for freely falling from the top of the screen to bottom with some rotation – Itisme Jun 24 '14 at 07:35
  • ok, in other words: how do you use it? – pskink Jun 24 '14 at 07:42
  • I am rotating the combined image with matrix.postRotate(angle). – Itisme Jun 24 '14 at 07:53
  • do you use it like Canvas.drawBitmap for example? – pskink Jun 24 '14 at 07:53
  • canvas.drawBitmap(bitmap, matrix, paint); – Itisme Jun 24 '14 at 07:54
  • so draw it two times: a shadow then a leaf? make sure to translate a Matrix for a second call – pskink Jun 24 '14 at 07:58
  • one more thing is there.When i touch the original image,the original image is moved away from the touched position.In the similar manner,the shadow also should move away like it is attached to the original image.i.e they must be like a group and the shadow should appear always at the bottom of the original image in rotating it. – Itisme Jun 24 '14 at 08:05
  • it should be like a leaf floating on the water.when leaf is rotated on the water with some movement,its shadow is also rotated with the same rotation without changing its relative position with respect to the leaf – Itisme Jun 24 '14 at 08:09
  • as i said: draw it twice – pskink Jun 24 '14 at 08:11
  • Superb yaar.It has worked.you have great logic.thanks a lot. – Itisme Jun 24 '14 at 10:16
  • @pskink - i am drawing two bitmaps on a canvas but then the second bitmap doesnot seem to draw at the correct positions, and on using `canvas.setRotate` the overlay is displayed at the back. could u please help ? – Rat-a-tat-a-tat Ratatouille Sep 15 '14 at 08:25

0 Answers0