title: Android Bitmap Transformation Math
body: <p>I need to combine 2 images into one.  Basically all i need to do is to overlay one of them on top of the other in the center of the image.  This needs to work on all major android devices.</p>
  
  <p>I have tried a number of things, but here is my code snippet as of right now (and yes I know it's messed up, we need to figure out delx and dely):</p>
  
  <pre><code>/* Rotate our original photo */
  //  final float scale = getResources().getDisplayMetrics().density;
      canvas.drawBitmap(bmp, 0f, 0f, null);
      final float overlay_scale_factor = .5f;
      final int overlaywidth = (int)(overlay.getWidth() * overlay_scale_factor);
      final int overlayheight = (int)(overlay.getHeight() * overlay_scale_factor);
      final int delx = overlaywidth;
      final int dely = overlayheight;
      Matrix mat = new Matrix();
      mat.postRotate(270);
      mat.postScale(overlay_scale_factor, overlay_scale_factor);
      //mat.postTranslate(-delx, -dely);
      canvas.drawBitmap(overlay, mat, null);
      /* Bottom image 'composite' is now a composite of the two. */
  </code></pre>
  
  <p>Any help is appreciated.  I know this is just math, but I'm not good at this kind of stuff.</p>
  
  <p>The first image, 'bmp' is 100% the size of the canvas.
  The second image, 'overlay' is the overlay that needs to be centered after it's rotated 270 degrees.</p>