title: Android: How do I scale a bitmap to fit the screen size using canvas/draw bitmap?
body: <p>I am taking an image and drawing it to the screen using canvas. I want to scale it based on the screen size. </p>
  
  <p>This is what I tried, but it cuts off a large chunk of the image:</p>
  
  <pre><code>DisplayMetrics metrics = context.getResources().getDisplayMetrics();
  int width = metrics.widthPixels;
  int height = metrics.heightPixels;
  
  Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.myimage);
  bitmap = Bitmap.createScaledBitmap(bitmap, width, height, false);
  
  Rect frameToDraw = new Rect(0, 0, width, height);
  RectF whereToDraw = new RectF(0, 0, width, height);
  
  canvas.drawBitmap(bitmap,frameToDraw,whereToDraw, paint);
  </code></pre>
  
  <p>I know I am doing a few things wrong, but I'm not exactly sure what. This code causes the image to exceed the size of the screen. I want it to be scaled to the size of the screen. I'll be drawing smaller images in too that I also will need to scale <em>according</em> to the size of the screen, though not to the full screen.</p>