我正在尝试将位图缩放到屏幕大小并将其设置为墙纸,但我注意到在某些设备上(屏幕有点宽),壁纸的高度有点凌乱 . 有人可以帮助我以正确的方式缩放图像吗?

这是我的代码:

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();
                }