2013-01-16 59 views
2

WallpaperManager在某些設備上縮小壁紙太小。我使用了下面的代碼。Android WallpaperManager縮放比特圖太小

Bitmap srcBitmap = ..... 
    WallpaperManager wm = WallpaperManager 
       .getInstance(getApplicationContext()); 
    int height = wm.getDesiredMinimumHeight(); 
    int width = wm.getDesiredMinimumWidth(); 
    wm.setBitmap(Bitmap.createScaledBitmap(srcBitmap, width , height , true); 

在Android 4.0.4銀河注意到壁紙填滿整個屏幕。但在2.3版的Galaxy S2上,壁紙只填充屏幕中央的一個小矩形。

問候,

MP5

回答

3

的問題是wm.getDesiredMinimumHeight();wm.getDesiredMinimumWidth();返回-1某些設備上。因此Bitmap.createScaledBitmap(srcBitmap, width , height , true);失敗,並使用srcBitmap的原始大小。

0

以及這將適合屏幕與您的位圖的寬度和高度

WallpaperManager wallmanage = (WallpaperManager) getSystemService(WALLPAPER_SERVICE); 
wallmanager.setBitmap(bitmap); 
wallmanager.suggestDesiredDimensions(w, h); 

where w = bitmap.getWidth(); 
and h = bitmap.getHeight();