Droid_Dev
Droid_Dev

Reputation: 1162

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

Upvotes: 8

Views: 1699

Answers (2)

Luke Taylor
Luke Taylor

Reputation: 9599

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.

Upvotes: 2

herbertD
herbertD

Reputation: 10955

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.

Upvotes: 1

Related Questions