問題描述
Android WallpaperManager 將位圖縮放得太小 (Android WallpaperManager scales Bitmap too small)
the WallpaperManager scales the wallpaper too small on some devices. I used the following code.
Bitmap srcBitmap = .....
WallpaperManager wm = WallpaperManager
.getInstance(getApplicationContext());
int height = wm.getDesiredMinimumHeight();
int width = wm.getDesiredMinimumWidth();
wm.setBitmap(Bitmap.createScaledBitmap(srcBitmap, width , height , true);
On the galaxy note with android 4.0.4 the wallpaper fills the full screen. But on galaxy s2 with 2.3 the wallpaper fills only a small rectangle in the center of the screen.
greetings,
mp5
‑‑‑‑‑
參考解法
方法 1:
the problem was that wm.getDesiredMinimumHeight();
and wm.getDesiredMinimumWidth();
return ‑1 on some devices. So Bitmap.createScaledBitmap(srcBitmap, width , height , true);
failed and the original size of srcBitmap
was used.
方法 2:
well this will fits the screen with your bitmap width and height
WallpaperManager wallmanage = (WallpaperManager) getSystemService(WALLPAPER_SERVICE);
wallmanager.setBitmap(bitmap);
wallmanager.suggestDesiredDimensions(w, h);
where w = bitmap.getWidth();
and h = bitmap.getHeight();