Android 动态壁纸缩放
我正在学习如何制作动态壁纸,但我有一个困境,我相信所有刚开始的人也有这样的困境。
有这么多分辨率的屏幕尺寸,我怎样才能使一组艺术品在代码中为所有版本重新缩放?我知道它已经完成了,因为我看到了很多应用程序中的图像,并且它们被重新缩放。
如果只是一张不需要任何定位的图像,那就很容易了,但我的问题是我必须重新调整背景图像以适合所有设备,我还有适合该背景上某个 x 和 y 位置的动画图像适合到位,这样看起来整个背景都在动画化,但只有一部分是动画化的(我的方式是远离 300 张逐帧动态壁纸图像)。
因此,背景图像需要重新缩放,动画也需要重新缩放到与背景图像相同的百分比,并且它们需要位于特定的 x 和 y 位置。
任何帮助将不胜感激,以便我能够继续下去。
我厌倦了一些事情,想我会为所有事情制作一个缩放器,例如:int scaler;然后在onSurfaceChanged中scaler = width /1024; //如果更大的图像是1024。这将为我提供一个可以在任何地方使用的比率。然后使用scaleBitmap进行相应缩放,方法是将缩放器乘以图像高度和宽度,并使用相同的缩放器来定位示例图像x,假设图像x为50,使用相同的东西缩放它x =缩放器* 50;应该负责缩放和定位,下一课就是如何将所有这些转换为 java,因为我是 java 新手,我曾经为 flash 和 php 编程,但这有很大不同,需要一些时间来适应。接下来的事情是如何平移宽度,当您将屏幕从一侧移动到另一侧时,如何使图像显示是我想出的下一个难题。现在,无论如何,它都只显示相同的宽度,即使宽度是表面显示的两倍。如果您得到答案或在某个地方我可以找到有关此问题的信息,我将不胜感激。
I am learning how to make live wallpapers, but I have a dilemma I'm sure all who start off have as well.
There is so many resolution screen sizes, how can I just make one set of artwork to be rescaled in code for all versions? I know it's been done as I seen the images in the apk's on a lot of them and they get rescaled.
If it was just one image that did not need any positioning that would be easy, but my problem is I have to get the background image rescaled to fit all devices, I also have animations that fit in a certain x and y position on that background image to fit in place so it looks like the whole background is being animated but only parts of it is (my way of staying away from 300 images of frame by frame live wallpapers).
So the background image needs to be rescaled and the animations need to be rescaled as well to the exact percentage as the background image and they need to sit in a specific x and y position.
Any help would be appreciated so I can get this going.
I tired a few things, figured I would make a scaler for everything example: int scaler; then in onSurfaceChanged scaler = width /1024; //if the bigger image is 1024. that will give me a ratio to work with everywhere. then scale accordingly using scaleBitmap by multiplying the scaler by the image height and width, and also use the same scaler for positioning example image x lets say is at 50, scale it using the same thing x = scaler * 50; that should take care of scaling and positioning, just how to translate all this into java is the next lesson, since I'm new to java, I used to program for flash and php but this is a lot different, take some getting used to. Next thing is how to pan the width, when you move your screen from side to side how to make the image show is the next puzzle I have figure out. Right now it just shows the same width no matter what even though the width is double what the surface shows. If you got an answer or somewhere I can find out the info on this one that would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,嗯,我只能说“欢迎来到现实世界”。您可以通过 onSurfaceChanged 将屏幕尺寸传递给您,是的,您的工作就是弄清楚如何根据此数据缩放所有内容。这就是为什么他们付给我们大笔钱。 :-)
您需要确保您的资源足够大,可以容纳您打算支持的最大显示器,因此您将始终缩小事物(这比扩展事物造成的扭曲要小得多)。
建议从此处的“屏幕独立最佳实践”开始:http://developer.android.com /guide/practices/screens_support.html
关于您寻求更多帮助的请求的其他评论...
这不是“简单”的编码——应用程序比壁纸更容易。 :-)
祝你好运...乔治
P.S.我还要再补充一件事:在某个地方,您可能想要检索启动器所需的壁纸的“所需最小宽度”,这样您就可以明确地理解 xPixels 中隐含的虚拟化。例如,在我的引擎构造函数中,我
的设备具有 320 像素宽度;我得到 mDW = 640;当我从一个屏幕滚动到另一个屏幕时,xPixels 每次都会改变 80...因为四个滚动(跨五个屏幕)应该使显示的艺术品数量加倍(这种效果称为“视差滚动”)。最右边的部分 xPixels 等于 0;中心(五个)部分的 xPixels = -160 等。
Well, um, all I can say is "Welcome to the real world." You get your screen dimensions passed to you via onSurfaceChanged, and yes, it is your job to figure out how to scale everything based on this data. That's why they pay us the big bucks. :-)
You will want to make sure your resources are large enough to fit the biggest display you intend to support, so you will always be shrinking things (which distorts much less than expanding things).
Suggest starting with "best practices for screen independence" here: http://developer.android.com/guide/practices/screens_support.html
Additional comments in re your request for more help...
This is not "easy" coding--apps are easier than wallpaper. :-)
Good luck...George
P.S. I'll throw in one more thing: somewhere along the line you might want to retrieve the "desired minimum width" of the wallpaper desired by the launcher, so you can explicitly understand the virtualization implicit in xPixels. For example, in my engine constructor, I have
My device has 320 pixel width; I get mDW = 640; as I scroll from screen to screen, xPixels changes by 80 each time...because four scrolls (across five screens) is supposed to double the amount of revealed artwork (this effect is called "parallax scrolling"). The rightmost section has xPixels equals 0; the center (of five) sections has xPixels = -160, etc.
我使用此代码片段来缩放一张图像以适应不同的屏幕尺寸。
确保边缘不包含重要信息,因为在某些屏幕比例下,边缘会从图片中缩小。
I've used this code snippet to scale one image to fit on different screen sizes.
Make sure that the edges don't contain vital information as it will be scaled out of the picture on some screen ratios.