2014-06-30 53 views
0

嗨我想在android中做一個壁紙應用程序。我無法將圖像設置爲設備屏幕大小。當我將其設置爲牆紙時,圖像也會失去其質量。我也嘗試了一些stackoverflow的答案,但沒有給我正確的結果。如何在不損失圖像質量的情況下將圖像大小適應設備屏幕大小?

這裏是我的代碼:

  public void onClick(View arg0) { 

      WallpaperManager myWallpaperManager= WallpaperManager.getInstance(getApplicationContext()); 

      DisplayMetrics metrics = new DisplayMetrics(); 
      getWindowManager().getDefaultDisplay().getMetrics(metrics); 
      // get the height and width of screen 
      int height = metrics.heightPixels; 
      int width = metrics.widthPixels; 
      try { 
       Bitmap bitmap=((BitmapDrawable)imgflag.getDrawable()).getBitmap(); 
       if(bitmap!=null) 
        myWallpaperManager.setBitmap(bitmap); 
       myWallpaperManager.suggestDesiredDimensions(width, height); 
       Toast.makeText(SingleItemView.this, "Wallpaper Set", Toast.LENGTH_SHORT).show(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 


     } 

我到底錯在這裏做什麼?

回答

0

我想你試圖設置縮略圖(縮放)的圖像到屏幕上。

試試這個代碼:

Bitmap bitmap = BitmapFactoty.decodeFile(path); // or decodeResource, decodeStream, etc 
    // depends on your source 

代替:

Bitmap bitmap=((BitmapDrawable)imgflag.getDrawable()).getBitmap(); 

此源必須包含大量位圖。

相關問題