title: android scale bitmap to screen dimension
body: <p>actually I'm trying to create simple app with wallpapers.</p>
  
  <p>I'm trying to scale my image to user device screen size.
  I'm using code like bellow:</p>
  
  <pre><code>/*
  
    DisplayMetrics metrics = new DisplayMetrics(); 
  
    getWindowManager().getDefaultDisplay().getMetrics(metrics); 
  
    int height = metrics.heightPixels; 
    int width = metrics.widthPixels; 
  
  */
  
  
  Display metrics = getWindowManager().getDefaultDisplay();
  
  int height = metrics.getHeight();
  int width = metrics.getWidth(); 
  float fourToThree;
  int wymiar;
  Bitmap mbitmap; //definicja zmiennej przechowującej bitmapę
  try {
  
      Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), cardBase.cardImages[position]);
      //UP - zapisanie obrazu z tablicy do zmiennej bitmapy
      /*if(height&gt;=width) {
          fourToThree = height * 0.75f;   //height
          wymiar = (int)Math.round(fourToThree);
          mbitmap = Bitmap.createScaledBitmap(myBitmap, height, wymiar, true);
      } else {    
          fourToThree = height * 0.75f;
          wymiar = (int)Math.round(fourToThree);
          mbitmap = Bitmap.createScaledBitmap(myBitmap, width, wymiar, true);
      }*/
      mbitmap = Bitmap.createScaledBitmap(myBitmap, width, height, true);
      myWallpaper.setBitmap(mbitmap);
      Toast.makeText(SelectedCard.this, "Wallpaper changed", Toast.LENGTH_LONG).show();
  }
  catch (IOException e) {
      e.printStackTrace();
      Toast.makeText(SelectedCard.this, "Sorry, an error occurred", Toast.LENGTH_LONG).show();
  }
  </code></pre>
  
  <p>I was trying many other ways but still have my image larger then device screen :(</p>
  
  <p>I'm testing it on <code>virtual phone</code> and I was trying to create image dit 160 dpi as a device screen, it's not working too.</p>
  
  <p>Can anyone tell me, how can I scale my image (jpg - 320 x 480 px, 300 dpi) to set it as a wallpaper on device ?</p>
  
  <p>Any ideas ?</p>
  
  <p>thanks :)</p>
  
  <p>Ps. sorry for text mistakes, English is my second language ;p</p>
  
  <hr>
  
  <p>Ok, i have something like that:</p>
  
  <p>imgView.setOnClickListener(new View.OnClickListener() {</p>
  
  <pre><code>        @Override
          public void onClick(View v) {
              WallpaperManager myWallpaper = WallpaperManager.getInstance(getApplicationContext());
              try
              /*{
                  myWallpaper.setResource(HdImageBase.HdImages[position]);
                  Toast.makeText(ImageMini.this, "Wallpaper changed", Toast.LENGTH_LONG).show();
              }*/
              {
                  DisplayMetrics metrics = new DisplayMetrics(); 
  
                  getWindowManager().getDefaultDisplay().getMetrics(metrics); 
  
                  int height = metrics.heightPixels; 
                  int width = metrics.widthPixels; 
                  float fourToThree;
                  int wymiar;
                  Bitmap mbitmap; //definicja zmiennej przechowującej bitmapę
  
                  Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), cardBase.cardImages[position]);
  
                  mbitmap = Bitmap.createScaledBitmap(myBitmap, width, height, true);
                  myWallpaper.setBitmap(mbitmap);
  
                  Toast.makeText(SelectedCard.this, "Wallpaper changed \n" + width + "\n" + height, Toast.LENGTH_LONG).show();
                  }
              catch (IOException e) {
                  e.printStackTrace();
                  Toast.makeText(SelectedCard.this, "Sorry, an error occurred", Toast.LENGTH_LONG).show();
              }
          }
      });
  </code></pre>
  
  <p>Width and height values are correct 320 x 480 but image which I'm setting as a wallpaper is still more bigger then my device scren.</p>
  
  <p>After test on my real phone LG L5 with new android (not sure which version). Image is set as wallpaper correct (in portrait mode - 1 image for all 5 "roll screens" without scaling).</p>
  
  <p>How can i tested it on other devices ? 
  Mean... is this portrait mode for wallpapers is available only in new android version ?</p>