title: Android: How to get bitmap's scaled width in onDraw()
body: <p>Simple question where the simple answer isn't working. I have a bitmap and I want to get its dimensions as scaled to the display by the system for different DPI screens within the onDraw() method. bitmap.width() returns its unscaled width successfully. However, bitmap.getScaledWidth() returns zero. I have tried getScaledWidth(canvas) and getScaledWidth(canvas.getDensity()), but both return 0. Indeed, canvas.getDensity() returns zero so I can't even calculate it manually. </p>
  
  <p>What am I doing wrong? </p>
  
  <p>Bit more detail. I'm using a custom view. The bitmap is declared in the class and loaded in the constructor. </p>
  
  <p>Edit:</p>
  
  <p>I've found that using:</p>
  
  <pre><code>        DisplayMetrics metrics = new DisplayMetrics();
          wm.getDefaultDisplay().getMetrics(metrics);
  </code></pre>
  
  <p>bitmap.getScaledHeight(metrics) returns the same value as bitmap.getHeight().</p>
  
  <p>It would appear that bitmap.getWidth() returns the dimension of the resident bitmap after it has been scaled, meaning there's no apparent way to get the bitmap's original width.</p>