title: How to decode a Bitmap to a certain filesize?
body: <p>I'm currently scaling down Bitmaps in order to avoid an OutOfMemoryException.  Is there a way to specify a file size to decode to?   So no matter what file size the input image is, it will be scaled down to the specified file size.</p>
  
  <p>I'm using the following code from <a href="http://androidbysravan.wordpress.com/category/outofmemory-exception-when-decoding-with-bitmapfactory/" rel="nofollow">http://androidbysravan.wordpress.com/category/outofmemory-exception-when-decoding-with-bitmapfactory/</a> until I can figure out a way to specify the output file size.</p>
  
  <pre><code>Bitmap bm = null; 
  BitmapFactory.Options options = new BitmapFactory.Options(); 
  options.inSampleSize = 10; 
  AssetFileDescriptor fileDescriptor =null; 
  try { 
      fileDescriptor = _context.getContentResolver().openAssetFileDescriptor(selectedImage,"r"); 
  } catch (FileNotFoundException e) { 
      e.printStackTrace(); 
  } 
  finally{ 
      try { 
          bm = BitmapFactory.decodeFileDescriptor(fileDescriptor.getFileDescriptor(), null, options); 
          fileDescriptor.close(); 
      } catch (IOException e) { 
          e.printStackTrace(); 
      } 
  } 
  return bm; 
  } 
  </code></pre>