Android WallpaperManager 裁剪图像
我正在开发一个简单的壁纸应用程序,其中包含我拥有的一些图像。它们是可绘制文件夹中的 .png 文件。
以下是一些代码片段:
WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
....
myWallpaperManager.setResource(R.drawable.image1);
无论我使用什么尺寸或分辨率,设置壁纸时都会裁剪原始图像。当我使用相同的图像作为背景时,它的尺寸正确并显示整个图像。我认为这可能是我的模拟器的问题,所以我尝试在实际设备(HTC eris)上运行它,但我遇到了同样的问题。我已经将图像设置为 eris 的屏幕尺寸和分辨率,但它仍在裁剪它。然后我将图像制作为仅一英寸高,分辨率为 100 dpi。阋神星上的像素化程度很高,但仍然裁剪了图像。
任何帮助将不胜感激。
我尝试添加一些图像来显示之前和之后的情况,但作为新用户,我无法这样做。
I am working on a simple wallpaper app of some images that I have. They are .png files in drawable folders.
Here are some code snippets:
WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
....
myWallpaperManager.setResource(R.drawable.image1);
No matter what size or resolution I seem to use, when the wallpaper is set it crops the original image. When I use the same image as a background it is the correct size and shows the entire image. I thought it might be a problem with my emulator so I have tried running it on an actual device (HTC eris) and I am having the same problem. I have made the image the screen size and resolution for the eris and it is still cropping it. I then made the image only one inch high and a resolution of 100 dpi. It was very pixelated on the eris, but still cropped the image.
Any help would be greatly appreciated.
I attempted to add some images to show the before and after, but as a newer user I was prevented from doing so.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查 http://developer.android.com/reference/ 返回的值android/app/WallpaperManager.html#getDesiredMinimumWidth() 和 http://developer.android.com/reference/android/app/WallpaperManager.html #getDesiredMinimumHeight() 并尝试使用这些值作为壁纸的尺寸。
Check the values returned by http://developer.android.com/reference/android/app/WallpaperManager.html#getDesiredMinimumWidth() and http://developer.android.com/reference/android/app/WallpaperManager.html#getDesiredMinimumHeight() and try to use these values as the dimensions of your wallpaper.
也许我可以帮忙。
请注意,您应该调用
suggestDesiredDimensions
,然后调用getDesiredMinimumWidth
和getDesiredMinimumHeight
来获取要缩放到的尺寸。Maybe I can help.
Note that you should call
suggestDesiredDimensions
, then callgetDesiredMinimumWidth
andgetDesiredMinimumHeight
to get the size to be scaled to.我也有同样的问题。我制作了一个与屏幕大小相同的图像,并向图像添加了填充,使其与 WallpaperManager getDesiredMinimumWidth() 和 getDesiredMinimumHeight() 一样大。
最好让一些代码自动添加填充,这就是我下面使用的。确保图像与屏幕大小相同。
I had the same problem. I made an image that is the size of the screen and adding padding to the image so that it is as large as the WallpaperManager getDesiredMinimumWidth() and getDesiredMinimumHeight().
It seemed better to have some code automatically add the padding so that is what I used below. Make sure the image is the same size as the screen.