2013-01-16 34 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();