title: android bitmap - best practice
body: <p>Developing a graphical app that should work for any screen size requires some thinking
  Usually I create high resolution graphics and the scale to fit the screen.</p>
  
  <p>I've seen a recommendation to avoid using "real pixels"
  I tried working with density and dp but it seems more complex then using the solution I use
  And couldn't find a better way to scale my graphics other then to use the device screen (real pixels)</p>
  
  <p>I created this class to scale my images (based on real pixels)
  This solves most of my problems (still some devices have different aspect ration)
  and seems to work fine.</p>
  
  <pre><code>public class BitmapHelper {
      // Scale and keep aspect ratio 
      static public Bitmap scaleToFitWidth(Bitmap b, int width) {
          float factor = width / (float) b.getWidth();
          return Bitmap.createScaledBitmap(b, width, (int) (b.getHeight() * factor), false);  
      }
  
      // Scale and keep aspect ratio     
      static public Bitmap scaleToFitHeight(Bitmap b, int height) {
          float factor = height / (float) b.getHeight();
          return Bitmap.createScaledBitmap(b, (int) (b.getWidth() * factor), height, false);  
      }
  
      // Scale and keep aspect ratio 
      static public Bitmap scaleToFill(Bitmap b, int width, int height) {
          float factorH = height / (float) b.getWidth();
          float factorW = width / (float) b.getWidth();
          float factorToUse = (factorH &gt; factorW) ? factorW : factorH;
          return Bitmap.createScaledBitmap(b, (int) (b.getWidth() * factorToUse), (int) (b.getHeight() * factorToUse), false);  
      }
  
      // Scale and dont keep aspect ratio 
      static public Bitmap strechToFill(Bitmap b, int width, int height) {
          float factorH = height / (float) b.getHeight();
          float factorW = width / (float) b.getWidth();
          return Bitmap.createScaledBitmap(b, (int) (b.getWidth() * factorW), (int) (b.getHeight() * factorH), false);  
      }
  }
  </code></pre>
  
  <p>and my questions are:</p>
  
  <ol>
  <li>Why avoiding "real pixels" is recommended? </li>
  <li>What is the best practice of scaling Bitmaps to screen (a good article of tutorial
  are more then welcome) </li>
  <li>What are the cons of using the method I use or what should I be aware of when using this method</li>
  </ol>
  
  <p>Thanks for your advise</p>
  
  <p>[Edit]
  I forgot to mention that I usually use SurfaceView for my apps (if it make any difference)</p>