title: stretch image using canvas android
body: <p>Hello I have two images and i am merging that images using canvas</p>
  
  <p>here is the below code</p>
  
  <pre><code>      Intent intent = getIntent();
  
         //bm is the image get from camera
          bm = BitmapFactory.decodeFile(intent.getStringExtra("getdata"));
  
         //this is simple white text image
          bm1 = BitmapFactory.decodeResource(getResources(), R.drawable.txt_made_hawk_nelson);
          imgSeletedPhoto = (ImageView) findViewById(R.id.imgSelectedPhoto);
  
          int width = bm.getWidth();
          int height = bm.getHeight();
  
          int maxWidth = (width &gt; bm1.getWidth() ? width : bm1.getWidth());
          int maxHeight = (height &gt; bm1.getHeight() ? height : bm1.getHeight());
  
  
          // calculate the scale - in this case = 0.4f
          float scaleWidth = ((float) maxWidth) / width;
          float scaleHeight = ((float) maxHeight) / height;
  
          Matrix matrix = new Matrix();
          matrix.postScale(scaleWidth, scaleHeight);          
      bmOverlay = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
  
      Canvas canvas = new Canvas(bmOverlay);
      //canvas.drawBitmap(bm, 0, 0, null);
      canvas.drawBitmap(bm1, 0, 50, null);
      imgSeletedPhoto.setImageBitmap(bmOverlay);
      } catch (Exception e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>i want to scale image and image should look like below</p>
  
  <p><img src="https://i.stack.imgur.com/1tn0y.png" alt="enter image description here"></p>
  
  <p>but instead of by doing above code it is looking like </p>
  
  <p><img src="https://i.stack.imgur.com/tmjmj.png" alt="enter image description here"></p>
  
  <p>XML code of this file is </p>
  
  <pre><code>         &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:weightSum="10" &gt;
  
  &lt;RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="0dp"
      android:layout_weight="7" &gt;   // this is covering 70% of screen
  
      &lt;ImageView
          android:id="@+id/imgSelectedPhoto"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_centerInParent="true" /&gt;
  &lt;/RelativeLayout&gt;
  
  &lt;RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="0dp"
      android:layout_weight="3"
      android:background="#baca9d"
      android:gravity="center"
      android:orientation="vertical"
      android:paddingLeft="10dp"
      android:paddingRight="10dp" &gt;
  </code></pre>
  
  <p>can any body help me how to <strong>stretch image and make it full from bottom and top side also and put text in center</strong></p>