Android 动态壁纸——OpenGL 与 Canvas

发布于 2024-11-17 03:45:03 字数 440 浏览 7 评论 0原文

我是一个相当“新手”的 Android 开发人员,我希望我的第一个项目是动态壁纸,但是我对于是否应该专注于 Canvas 还是 OpenGL 感到矛盾。作为新手,我知道我应该首先掌握 Canvas,因为它更容易使用,但我更喜欢从我感兴趣的现实世界项目中学习,即使有时有点倒退。

我之前以非常基本的方式使用过两者,并且我了解它们的一般概念,但我不确定它们如何转移到动态壁纸领域。我认为动态壁纸不需要 OpenGL 的全面速度,因为以最大 FPS 运行只会过度消耗电池,但同时我担心使用 Canvas 会导致延迟和在执行更改主屏幕等操作时出现口吃。

我一直倾向于使用 OpenGL ES 2.0,既是为了保持最佳性能,也是因为我对壁纸的最初想法涉及大量分层,我不确定 Canvas 是否有能力,但我想听听更有经验的开发人员的意见或者说,使用 OpenGL 所涉及的所有额外工作(尤其是与动态壁纸相关的工作,根据我所读到的内容)都是值得的。

I am a fairly "newb" Android developer, and I would like one of my first projects to be a live wallpaper, however I am conflicted on whether I should be focusing on Canvas or OpenGL for it. Being new to this I know I should master Canvas first since it is easier to use, but I prefer to learn from real world projects that I have an interest in, even if it's a little backwards at times.

I have used both before in very basic ways, and I understand the general concepts to them, but I am not sure how they transfer over to the realm of live wallpapers. I figure that the full blown speed of OpenGL isn't required on a live wallpaper, since running it at max FPS would just run down the battery more than it necessary, but at the same time I am worried that using Canvas would cause lags and stutters when doing things like changing home screens.

I have been leaning towards using OpenGL ES 2.0, both to keep performance optimal and because my initial ideas for the wallpaper involve a lot of layering that I am not sure Canvas is capable of, but I'd like a more experienced developers opinion on whether or not all of the extra work involved in using OpenGL (especially in relation to live wallpapers, from what I've read) is worth it.

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

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

发布评论

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

评论(2

枫以 2024-11-24 03:45:03

如果您可以只在画布上绘图(例如 SDK 中的立方体示例),那么工作量就会少得多。由于动画的简单性(无位图),立方体能够毫无困难地实现高帧速率。

如果要使用 OpenGL,则需要使用补充包,例如 GLWallpaperService、AndEngine 或 RenderScript。

http://www.rbgrn.net/content/354- glsurfaceview-adapted-3d-live-wallpapers

http://www.andengine.org/forums/tutorials/live- wall-template-t258.html

浏览 Android 源代码,了解如何使用 RenderScript 实现库存壁纸(例如草、银河)。此链接可能有效,但不能保证:http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.1.1_r1/com/android/wallpaper/ (然后滚动直到壁纸)

Moonblink 已经停止了他的项目,但如果你真的很热衷,你可以尝试从这里开始研究他的作品(Substrate):http://code.google.com/p/moonblink/source/浏览/wiki/Setup.wiki

If you can get away with just drawing to a canvas (e.g. cube example in SDK), that's much less work. Because of the simplicity of the animation (no bitmaps), the cube is able to achieve a high frame rate without difficulty.

If you want to use OpenGL, you will need to use a supplemental package, such as GLWallpaperService, AndEngine, or RenderScript.

http://www.rbgrn.net/content/354-glsurfaceview-adapted-3d-live-wallpapers

http://www.andengine.org/forums/tutorials/live-wallpaper-template-t258.html

Browse the Android source code to see how the stock wallpapers (e.g. Grass, Galaxy) are implemented using RenderScript. This link may work, but no guarantees: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.1.1_r1/com/android/wallpaper/ (then scroll down to the wallpapers)

Moonblink has discontinued his project, but if you're really keen, you can try researching his work (Substrate) starting here: http://code.google.com/p/moonblink/source/browse/wiki/Setup.wiki

埋情葬爱 2024-11-24 03:45:03

我最终在项目进行到一半时使用了 OpenGL,事实证明画布绘制对于我想要实现的目标来说太慢了。使用 OpenGL 带来了巨大的性能提升。不幸的是我不得不重构我的代码,所以我建议从一开始就使用 OpenGL。 OpenGL 支持脏渲染,并且壁纸服务的结构不依赖于渲染事物的方式,因此您仍然能够创建不会耗尽电池的壁纸。实际上,精心设计的壁纸在隐藏时不会呈现。由于 Android 附带的壁纸不遵循这种模式,因此动态壁纸现在有了“耗电”的坏名声。真是可惜了..

I ended up using OpenGL as halfway through the project, canvas drawing proved to be too slow for what I was trying to achieve. Using OpenGL caused a massive performance boost. Unfortunately I had to refactor my code, so I would reccomend using OpenGL from the start. Dirty rendering is supported by OpenGL as well as the wallpaperservice's structure doesn't rely on the way you render things so you would still be able to create a wallpaper that doesn't drain the battery. Actually a well programmed wallpaper doesn't render when it's hidden. As the wallpapers shipped with android don't follow that pattern, live wallpapers now have the bad name of being battery suckers. Really a shame..

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