使用代码调整壁纸大小?
您能告诉我根据设备处于纵向还是横向模式使用代码调整主屏幕壁纸大小的最佳方法吗?
我们希望确保它可以在许多设备上运行。
请提供代码示例。
我们目前用这个来设置壁纸:
myWallpaperManager.setResource(R.drawable.thewallpaper);
壁纸也是一个png文件。
更新:
基于 coder_for_life22 的代码,我将其更改为:
try {
myWallpaperManager.setResource(R.drawable.kabaday1);
myCurrentImageName = "kabaday1";
Bitmap myBitmap = BitmapFactory.decodeResource(context.getResources(),
R.drawable.kabaday1);
Bitmap bitmapResized = Bitmap.createScaledBitmap(myBitmap, 600, 300,
false);
myWallpaperManager.setBitmap(bitmapResized);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
它缩放图像,但 Android 正在重新显示并以与缩小之前相同的图像尺寸扩展图像,只是这次图像质量开启模糊的一面仍然看起来放大了,没有显示出应该缩小的整个图像。
奇怪的行为。也许我需要添加一些更多的编码,这样它才能真正缩小并保持清晰。至少我认为应该这样做,因为图像应该更小。
有很多应用程序在做同样的事情。我只希望我知道他们是如何做到的。
谢谢。
Can you tell me the best way to resize a home screen wallpaper using code based on wether the device is in portrait or landscape mode?
We wish to make sure it will work on many devices.
Please provide code samples.
We are currently using this to set the wallpaper:
myWallpaperManager.setResource(R.drawable.thewallpaper);
The wallpaper is also a png file.
Update:
Based on the code from coder_for_life22, I changed it to this:
try {
myWallpaperManager.setResource(R.drawable.kabaday1);
myCurrentImageName = "kabaday1";
Bitmap myBitmap = BitmapFactory.decodeResource(context.getResources(),
R.drawable.kabaday1);
Bitmap bitmapResized = Bitmap.createScaledBitmap(myBitmap, 600, 300,
false);
myWallpaperManager.setBitmap(bitmapResized);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
It scales the image but Android is re-displaying and expanding the image with the same image size as it did before the scale down, only this time the image quality is on the fuzzy side and still seems zoomed in and not showing the entire image that should be scaled down.
Strange behaviour. Maybe there is some more coding I need to add to this so it really scales down and remains sharp. At least I think it should do that because the image should be smaller.
There are many apps out there doing the same thing. I only wish I knew how they are doing it.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要使用此
编辑来调整图像大小:您可能还需要更改您正在使用的图像视图的scaleType。通过将其插入到 imageview 所在的 xml 中。
或者您可以通过将其插入到上面的代码中以编程方式完成此操作。
这应该可以消除您所看到的放大外观。
You will need to resize the image using this
EDIT: You may also need to change the scaleType of the imageview you are using. by inserting this in your xml where imageview is located.
OR you can do it programmatically by inserting this in your above code.
That should get rid of the zoomed in look you are getting.