title: How to resize bitmap to the size of another Bitmap?
body: <p>In my app I take a old picture from the gallery, a new picture from the phone camera and blend them. In order to do that I need both Bitmaps to be the same size. When I download a pic from the internet and use it with a new pic from the phone the app works, but when I take a pic that I took on my phone as the pic from the gallery the app crashes when I resize it. By the way the whole app is in horizontal mode. How do I resize the Bitmaps correctly so my app wont crash?</p>
  
  <p>This is my code for resizing:</p>
  
  <pre><code>public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) {
      int width = bm.getWidth();
      int height = bm.getHeight();
      float scaleWidth = ((float) newWidth) / width;
      float scaleHeight = ((float) newHeight) / height;
      // CREATE A MATRIX FOR THE MANIPULATION
      Matrix matrix = new Matrix();
      // RESIZE THE BIT MAP
      matrix.postScale(scaleWidth, scaleHeight);
  
      // "RECREATE" THE NEW BITMAP
      Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
      return resizedBitmap;
  }
  </code></pre>
  
  <p>And this is how I used it:</p>
  
  <p>byte[]byteArray=getIntent().getByteArrayExtra("image");
                  Bitmap tmp=BitmapFactory.decodeByteArray(byteArray,0,byteArray.length);</p>
  
  <pre><code>            operation = Bitmap.createBitmap(tmp.getWidth(), tmp.getHeight(), Bitmap.Config.ARGB_8888);
              Canvas c = new Canvas(operation);
              Paint paint = new Paint();
              tmp.setDensity(c.getDensity());
  
              c.drawBitmap(tmp, 0f, 0f, paint);
              tmp.recycle();
  
  
  
              String stringUri = null;
              Bundle extras = getIntent().getExtras();
              if (extras != null &amp;&amp; extras.containsKey("KEY")) {
                  stringUri= extras.getString("KEY");
              }
              Uri uri;
              uri = Uri.parse(extras.getString("KEY"));
  
              try {
                   bmp = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
              } catch (FileNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  
              bmp.setDensity(c.getDensity());
              bmp=getResizedBitmap(bmp, operation.getWidth(), operation.getHeight());
  
  
  
              myView = new MainView(this, operation, bmp);
              FrameLayout preview = (FrameLayout) findViewById(R.id.preview);
              preview.addView(myView);
  </code></pre>