Android设置壁纸出错了

发布于 2024-12-27 13:45:09 字数 600 浏览 2 评论 0原文

所以我很久以前就在开发壁纸更换器并发布了它。一段时间后,我开始收到壁纸尺寸调整不正确的评论。我还尝试了不同尺寸的鸸鹋,它们是正确的。我正确地缩放位图等,但不知何故,android倾向于将壁纸重新缩放得更大!有办法避免吗? 我的代码:

Display display = parent.getWindowManager().getDefaultDisplay(); 
                    int width = display.getWidth();
                    int height = display.getHeight();
                    Bitmap scaled = Bitmap.createScaledBitmap(wallpaper, width, height, true);
                WallpaperManager wm = WallpaperManager.getInstance(getContext());
                wm.setBitmap(scaled);

我也一直在尝试其他方法,但似乎没有任何帮助,即使我事后检查重新缩放的壁纸尺寸是否正确等。:( 有什么想法吗?

So I was developing wallpaper changer long time ago and got it released. After a while I started receiving comment the wallpaper not resizing correctly. Also I tried on different sizes of emus and they were right. I scale the bitmap correctly etc. but somehow android tends to rescale the wallpaper even bigger! Is there way to avoid that?
My code:

Display display = parent.getWindowManager().getDefaultDisplay(); 
                    int width = display.getWidth();
                    int height = display.getHeight();
                    Bitmap scaled = Bitmap.createScaledBitmap(wallpaper, width, height, true);
                WallpaperManager wm = WallpaperManager.getInstance(getContext());
                wm.setBitmap(scaled);

I've been trying other ways too but nothing seems help, even if I afterwards check if the rescaled wallpaper is right size etc. :(
Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柠北森屋 2025-01-03 13:45:09

我想您可以使用 WallpaperManager 指定的尺寸来调整壁纸的大小.getDesiredMinimumWidth()WallpaperManager.getDesiredMinimumHeight(),而不是显示尺寸。这样,即使是自定义家庭应用程序设置的要求(例如设备制造商和/或服务提供商可能设置的要求)也将得到尊重,这意味着您的应用程序具有(大)更大的兼容性。

I suppose you could resize the wallpapers using the size specified by WallpaperManager.getDesiredMinimumWidth() and WallpaperManager.getDesiredMinimumHeight(), instead of the display size. That way, even the requirements set by custom home applications (like those possibly set by device manufacturers and/or service providers) will be respected, meaning a (much) larger compatibility for your app.

还在原地等你 2025-01-03 13:45:09

我遇到了同样的问题,调整壁纸大小后尺寸相同,但分辨率不同。

就我而言,该代码解决了问题:

DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);

        int height = metrics.heightPixels;
        int width = metrics.widthPixels;

        Bitmap bitmap = Bitmap
                .createScaledBitmap(whatever, width, height, true);

I had the same problem, after resize wallpaper had the same size, but diffrent resolution.

In my case that code solved problem:

DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);

        int height = metrics.heightPixels;
        int width = metrics.widthPixels;

        Bitmap bitmap = Bitmap
                .createScaledBitmap(whatever, width, height, true);
梦太阳 2025-01-03 13:45:09

我必须创建覆盖图像。

  1. 创建大小为 WallpaperManager.getDesiredMinimumWidth() x WallpaperManager.getDesiredMinimumHeight()

  2. 将位图大小调整为屏幕尺寸, Display display = getWindowManager().getDefaultDisplay(); bmp = Bitmap.createScaledBitmap(bmp, display.getWidth(), display.getHeight(), false); code>

  3. 将壁纸覆盖在空白图像的中心。并将 Overlay 设置为壁纸。

I had to create overlay image.

  1. Create a blank image with size of WallpaperManager.getDesiredMinimumWidth() x WallpaperManager.getDesiredMinimumHeight()

  2. Resize your bitmap to screen size with, Display display = getWindowManager().getDefaultDisplay(); bmp = Bitmap.createScaledBitmap(bmp, display.getWidth(), display.getHeight(), false);

  3. Overlay your wallpaper on center of blank image. And set Overlay as wallpaper.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文