Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i merge two bitmap one over another at selected point on the first image in android?

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??

like image 328
Droid_Dev Avatar asked Jul 04 '12 05:07

Droid_Dev


2 Answers

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.
like image 165
Luke Taylor Avatar answered Nov 01 '22 16:11

Luke Taylor


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.

like image 26
herbertD Avatar answered Nov 01 '22 15:11

herbertD