title: Android - Converting Bitmap to Drawable from SDCard
body: <p>Hey having something odd showing up when I convert a Bitmap from SDCard to a Drawable with regards to resizing:</p>
  
  <pre><code>String sdDir = Environment.getExternalStorageDirectory().getPath();
  String filename = "test.png"; //420px X 420px
  Drawable tmpDraw;
  Bitmap tmpBit = BitmapFactory.decodeFile(sdDir+filename);
  
  Log.e("BAH","Bitmap height:"+tmpBit.getHeight()); //420
  
  tmpDraw = (Drawable) new BitmapDrawable(getResources(),tmpBit);
  int height = tmpDraw.getMinimumHeight();
  
  Log.e("BAH","Drawable height:"+height); //420
  </code></pre>
  
  <p>I'm assuming that I need a point of reference to scale from? If a file is read from SDCard is it classed as MDPI and this is why it gets rescaled? I'm currently using a Nexus 7 to test which is TVDPI. I would like the scaling to occur as if the Bitmap is in HDPI.</p>
  
  <p>Any suggestions would be greatly appreciated!</p>
  
  <p>Think I've cracked it:</p>
  
  <pre><code>String sdDir = Environment.getExternalStorageDirectory().getPath();
  String filename = "test.png"; //420px X 420px
  Drawable tmpDraw;
  
  BitmapFactory.Options options = new BitmapFactory.Options();
  DisplayMetrics metrics = getApplicationContext().getResources().getDisplayMetrics();
  options.inDensity = 240; //Being DPI for HDPI
  options.inTargetDensity=metrics.densityDpi; //Being current DPI
  //inDensity/inTargetDensity are a ratio
  
  Bitmap tmpBit = BitmapFactory.decodeFile(sdDir+filename,options);
  
  Log.e("BAH","Bitmap height:"+tmpBit.getHeight()); //373 Correct for TVDPI
  
  tmpDraw = (Drawable) new BitmapDrawable(getResources(),tmpBit);
  int height = tmpDraw.getMinimumHeight();
  
  Log.e("BAH","Drawable height:"+height); //373 Correct for TVDPI
  </code></pre>
  
  <p>Is this an acceptable way to do it?</p>