title: Crop-to-fit image in Android
body: <p>I've been trying this for some time, I would like to create a wallpaper from a <code>Bitmap</code>. Let's say the desired wallpaper size is 320x480, and the source image size is 2048x2048. </p>
  
  <p>I'm not sure whether crop-to-fit is the right term, but what I would like to achieve is to get most part of the picture that has the equal ratio as the desired wallpaper size (320x480).</p>
  
  <p>So in this case, I would like to get 2048x1365 or (1365.333... to be exact) from the source <code>Bitmap</code>, and scale it down to 320x480.</p>
  
  <p>The technique that I have tried is:</p>
  
  <p>1) Crop the Bitmap into 2048x1365 first</p>
  
  <pre><code>bm = Bitmap.createBitmap(bm, xOffset, yOffset, 2048, 1365);
  </code></pre>
  
  <p>2) Scale it down to 320x480</p>
  
  <pre><code>bm = Bitmap.createScaledBitmap(bm, 320, 480, false);
  </code></pre>
  
  <p>which produced OutOfMemory error.</p>
  
  <p>Is there any way to achieve this?</p>
  
  <p>Regards,</p>
  
  <p>dezull</p>