所以在玩了很多之后,我发现它在获得屏幕高度、位图高度和宽度的尺寸并使用它之后相当简单
bitmapWidth = (bitmapWidth * screenHeight) / bitmapHeight;
我可以将新尺寸传递给位图高度
bitMapHeight = bitmap_Width;
我是新人,所以如果这是一个不好的解决方案,请纠正我,但在 2 部不同的手机和 2 部不同的平板电脑上尝试过,它适用于我的情况,这是我的完整方法调用;
private void setWallPaper() throws IOException {
int screenHeight;
int screenWidth;
Display display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenHeight = size.y;
screenWidth = size.x;
Bitmap bitmap = ((BitmapDrawable)
WallpaperView.getDrawable()).getBitmap();
int bitmapWidth = bitmap.getWidth();
int bitmapHeight = bitmap.getHeight();
bitmapWidth = (bitmapWidth * screenHeight) / bitmapHeight;
bitmapHeight = bitmapWidth;
WallpaperManager wallpaperManager =
WallpaperManager.getInstance(getActivity());
wallpaperManager.setBitmap(bitmap.createScaledBitmap
(bitmap,bitmapWidth,bitmapHeight,true));
Snackbar.make(getActivity().findViewById(R.id.wallLayout),
"Wallpaper Set "+"height"+ bitmapHeight+ "width"+bitmapWidth,
Snackbar.LENGTH_LONG)
.show();
}