0

我目前正在使用以下代码片段来设置我的墙纸背景。我的问题是完整的图像没有出现在壁纸上。它总是从墙纸的底部和侧面视图中被剪裁和丢失对象。我尝试裁剪照片,调整图像大小,还尝试更改分辨率以匹配我的模拟器。这些都不起作用。你们有谁知道如何使用下面的代码显示完整的图像:

Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.testimg2);
try {
      wpm.setBitmap(background);
}catch(...){
....
}

更新的代码(仍然裁剪图像):

int width = display.getWidth();
 int height = display.getHeight();
 Log.v("WALLPAPER", "width and height are " + width + " " + height);
 Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.testimg2);
 Bitmap scaled = Bitmap.createScaledBitmap(background, width, height, true);
4

1 回答 1

2

The problem is probably the resolution the wallpaper manager desires. It's probably double the width of the screen, and it resizes the wallpaper so it fits the desired parametres. Try this to find out what the desired wallpaper resolution is, using

int minH, minW;
WallpaperManager myWallpaperManager  = WallpaperManager.getInstance(getApplicationContext());
minH = myWallpaperManager.getDesiredMinimumHeight();
minW = myWallpaperManager.getDesiredMinimumWidth();
Log.d("TAG", "The desired wallpaper height is: " + minH + "; and the desired width is:" + minW);

After that make a Bitmap.createScaledBitmap with minH and minW. And remember to put this when you create the bitmap:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
于 2012-12-17T21:31:41.263 回答