8

How can i merge two different images as one. Also i need to merge the second image at a particular point on the first image. Is it posible in android??

Droid_Dev
  • 1,162
  • 1
  • 8
  • 25
  • post you required screen shot for help.... – Md Abdul Gafur Jul 04 '12 at 05:28
  • 1
    hi Md Abdul Gafur, I need to merge one image over another. I have done that.. but now i need to do the merging in such a manner that i can add the second image at a position where i need to place it...(eg:Suppose a persons picture as the first image and a bubble as the second image.. i need to place the bubble on the to of his head). – Droid_Dev Jul 04 '12 at 05:36

2 Answers2

2

This should work:

  • Create a canvas object based from the bitmap.
  • Draw another bitmap to that canvas object (methods will allow you specifically set coordinates).
  • Original Bitmap object will have new data saved to it, since the canvas writes to it.
Bart
  • 19,692
  • 7
  • 68
  • 77
Luke Taylor
  • 9,481
  • 13
  • 41
  • 73
1

I guess this function can help you:

private Bitmap mergeBitmap(Bitmap src, Bitmap watermark) {
      if (src == null) {
         return null;
      }
      int w = src.getWidth();
      int h = src.getHeight();

      Bitmap newb = Bitmap.createBitmap(w, h, Config.ARGB_8888);
      Canvas cv = new Canvas(newb);

      // draw src into canvas
      cv.drawBitmap(src, 0, 0, null);

      // draw watermark into           
      cv.drawBitmap(watermark, null, new Rect(9, 25, 154, 245), null);

      // save all clip
      cv.save(Canvas.ALL_SAVE_FLAG);

      // store
      cv.restore();

      return newb;
   }

It draws the water mark onto "src" at specific Rect.

herbertD
  • 10,657
  • 13
  • 50
  • 77