title: Merge two bitmaps in android
body: <p>I want to merge two bitmaps, here is my code</p>
  
  <pre><code>// Camera arg conversion to Bitmap
                      Bitmap cameraBitmap = BitmapFactory.decodeByteArray(arg0, 0,
                              arg0.length);
                      Bitmap back = Bitmap.createBitmap(cameraBitmap.getWidth(),
                          cameraBitmap.getHeight(), Bitmap.Config.ARGB_8888);
                      Canvas cam = new Canvas(back);
                      cam.drawBitmap(cameraBitmap, matrix, null);
  
  
                      // FrameLayout to Bitmap
                      FrameLayout mainLayout = (FrameLayout) findViewById(R.id.frame);
                      Bitmap foreground = Bitmap.createBitmap(mainLayout.getWidth(),
                              mainLayout.getHeight(), Bitmap.Config.ARGB_8888);
                      Canvas c = new Canvas(foreground);
                      mainLayout.draw(c);
  
                      Bitmap cs = null;
                      cs = Bitmap.createBitmap(foreground.getWidth(), cameraBitmap.getHeight(), Bitmap.Config.ARGB_8888); 
  
                      Canvas comboImage = new Canvas(cs); 
                      comboImage.drawBitmap(cameraBitmap, 0f, 0f, null); 
                      comboImage.drawBitmap(foreground, 0f, cameraBitmap.getHeight(), null); 
  
                      FileOutputStream fos = null;
                      try {
                          fos = new FileOutputStream(file);
                          if (fos != null) {
                              cs.compress(Bitmap.CompressFormat.PNG, 90, fos);
                              fos.close();
                          }
                      } catch (Exception e) {
                          e.printStackTrace();
                      }   
  </code></pre>
  
  <p>The camera image should become background, and foreground as top image. I've tried from 
  <a href="http://www.jondev.net/articles/Combining_2_Images_in_Android_using_Canvas" rel="noreferrer">Combining 2 Images in Android using Canvas</a>  but it didn't help me. Any idea.? Thanks</p>