Android设置壁纸出错了
所以我很久以前就在开发壁纸更换器并发布了它。一段时间后,我开始收到壁纸尺寸调整不正确的评论。我还尝试了不同尺寸的鸸鹋,它们是正确的。我正确地缩放位图等,但不知何故,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想您可以使用 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.
我遇到了同样的问题,调整壁纸大小后尺寸相同,但分辨率不同。
就我而言,该代码解决了问题:
I had the same problem, after resize wallpaper had the same size, but diffrent resolution.
In my case that code solved problem:
我必须创建覆盖图像。
创建大小为
WallpaperManager.getDesiredMinimumWidth()
xWallpaperManager.getDesiredMinimumHeight()
将位图大小调整为屏幕尺寸,
Display display = getWindowManager().getDefaultDisplay();
bmp = Bitmap.createScaledBitmap(bmp, display.getWidth(), display.getHeight(), false);
code>将壁纸覆盖在空白图像的中心。并将 Overlay 设置为壁纸。
I had to create overlay image.
Create a blank image with size of
WallpaperManager.getDesiredMinimumWidth()
xWallpaperManager.getDesiredMinimumHeight()
Resize your bitmap to screen size with,
Display display = getWindowManager().getDefaultDisplay();
bmp = Bitmap.createScaledBitmap(bmp, display.getWidth(), display.getHeight(), false);
Overlay your wallpaper on center of blank image. And set Overlay as wallpaper.