【问题标题】:Android Wallpaper Background安卓壁纸背景
【发布时间】:2012-05-20 16:23:23
【问题描述】:

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

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

【问题讨论】:

标签: android background wallpaper


【解决方案1】:

问题可能是壁纸管理器想要的分辨率。它可能是屏幕宽度的两倍,并且它会调整壁纸的大小以适合所需的参数。尝试使用

找出所需的壁纸分辨率是多少
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);

然后用 minH 和 minW 创建一个 Bitmap.createScaledBitmap。并且记得在创建位图时把它放好:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多