Merge two images one below the other in android by adding pixels
<p>I am trying to join images and form 1 single image.This is done to send the image to the server.</p>

<pre><code>    //Obtain the bitmaps from drawabl folder
    Bitmap bm1 = BitmapFactory.decodeResource(getResources(), R.drawable.image);
    Bitmap bm2 = BitmapFactory.decodeResource(getResources(), R.drawable.img);
    //Create a buffer
   ByteBuffer buffer3 = ByteBuffer.allocate((bm1.getHeight()+bm2.getHeight()) *        (bm1.getRowBytes()+bm2.getRowBytes()));
    //copy the pixels to buffer
        bm2.copyPixelsToBuffer(buffer3);
        bm1.copyPixelsToBuffer(buffer3);
    //Covert to byteArray
        byte[] bytes = buffer3.array();
        int leftovers = buffer3.remaining();
        buffer3.compact();

//Finally forming a bitmap

  Bitmap bitmap = BitmapFactory.decodeByteArray(bytes , 0, bytes.length);   
  ImageView img = (ImageView) findViewById(R.id.imgV);
  img.setImageBitmap(bitmap);
</code></pre>

<p>But the problem I am facing is my "bitmap" is coming as null.</p>

<p>Can anyone please help me joining images.</p>