title: Resize Bitmap to 512x512 Without changing original aspect ratio
body: <p>I have a created bitmaps. Sizes are not specific.  Sometimes 120x60 , 129x800 , 851x784. Its not have a specific value... I want to make these bitmaps resizing to 512x512 always but without changing original images aspect ratio. And without cropping. New image must have canvas 512x512 and original image must be center without any cropping.</p>
  
  <p>I was resizing my bitmaps with this function but it makes images really bad because image fitting X and Y . I don't want image to fit x and y on same time fits one of it and keeps its aspect ratio.</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);
          bm.recycle();
          return resizedBitmap;
      }
  </code></pre>
  
  <p>What I have;</p>
  
  <p><a href="https://i.stack.imgur.com/zaCLS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zaCLS.png" alt="enter image description here"></a></p>
  
  <p>What I want;</p>
  
  <p><a href="https://i.stack.imgur.com/x3yfj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x3yfj.png" alt="enter image description here"></a></p>