I'm trying to scale a bitmap to screen size and set it as wallpaper, but I've noticed on some devices(where the screen is a bit wider) the wallpaper is a little messy in height. Can someone help me scale the image in right way?
Here is my code:
int widthPx = getWindowManager().getDefaultDisplay()
.getWidth();
int heightPx = getWindowManager().getDefaultDisplay()
.getHeight();
// bmp = Bitmap.createScaledBitmap(bmp, widthPx, heightPx,
// true);
BitmapDrawable drawable = (BitmapDrawable) background
.getDrawable();
Bitmap bitmap = drawable.getBitmap();
try {
WallpaperManager myWallpaperManager = WallpaperManager
.getInstance(getApplicationContext());
Bitmap resizedBitmap = Bitmap.createScaledBitmap(
bitmap,
myWallpaperManager.getDesiredMinimumWidth(),
myWallpaperManager.getDesiredMinimumHeight(),
true);
myWallpaperManager.setWallpaperOffsetSteps(1, 1);
myWallpaperManager.suggestDesiredDimensions(widthPx,
heightPx);
myWallpaperManager.setBitmap(resizedBitmap);
Toast.makeText(BackgroundPreview.this,
getString(R.string.wallpaper_set),
Toast.LENGTH_SHORT).show();
finish();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(BackgroundPreview.this,
getString(R.string.error_setting_wallpaper),
Toast.LENGTH_SHORT).show();
}