【问题标题】:(android) set homescreen wallpaper with the correct dimensions(android) 设置具有正确尺寸的主屏幕壁纸
【发布时间】:2011-11-19 13:47:41
【问题描述】:

我目前正在构建一个应用程序,我想更换壁纸。所以这是我的代码。 当用户设置壁纸时,我会保存共享首选项的路径。

Display display = getWindowManager().getDefaultDisplay();

SharedPreferences prefs = getBaseContext().getSharedPreferences(PREFS_NAME,0);
if (prefs.contains(d)) {
    Bitmap bitmapOrg = BitmapFactory.decodeFile(prefs.getString(d, ""));

    int newWidth = display.getWidth();
    int newHeight = display.getHeight();

    Bitmap resizedBitmap =Bitmap.createScaledBitmap(bitmapOrg, newWidth, newHeight, true);
    myWallpaperManager.setBitmap(resizedBitmap);
}

使用该代码,我得到了类似 this 的内容,而我想显示类似 this 的图片

知道怎么做吗?

【问题讨论】:

    标签: android dimensions wallpaper homescreen


    【解决方案1】:

    好的,我发现了如何做到这一点。 首先我创建一个新的位图

    newBmp = Bitmap.createBitmap(display.getWidth(), display.getHeight(), Bitmap.Config.ARGB_8888);
    

    然后调整原始位图的大小:

    Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmapOrg, scaleWidth, scaleHeight, false);
    

    然后我调用叠加将两个图像绘制在一起。第一个图像具有显示器的尺寸,第二个是图像。

    vate Bitmap overlay(Bitmap bmp1, Bitmap bmp2, int left, int imgsize) {
       Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
       Canvas canvas = new Canvas(bmOverlay);
       canvas.drawBitmap(bmp1, new Matrix(), null);
       canvas.drawBitmap(bmp2, left-(imgsize/2), 15, null);
       return bmOverlay;
    }
    

    最后:

    myWallpaperManager.setBitmap(newB);
    

    【讨论】:

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