简体   繁体   English

有趣的动态壁纸行为

[英]Interesting Live Wallpaper Behavior

I just started making some of my first live wallpapers in Android, and I noticed an interesting behavior regarding the PixelFormat . 我刚刚开始在Android中制作一些第一张动态壁纸,并且注意到有关PixelFormat的有趣行为。 If I use the SurfaceHolder 's default PixelFormat , my live wallpaper is a bit laggy. 如果我使用SurfaceHolder的默认PixelFormat ,那么我的动态壁纸会有点滞后。 If I set the PixelFormat to RGB_565 it seems to fix this problem. 如果将PixelFormat设置为RGB_565 ,似乎可以解决此问题。 This really should not be too surprising. 这确实不应该太令人惊讶。 What was odd was profiling reveal that it was taking just as long to do the rendering in both formats. 奇怪的是,剖析显示这两种格式的渲染花费了相同的时间。 Could anyone explain this behavior. 任何人都可以解释这种行为。

Thanks, Xor 谢谢,Xor

---Edit--- If it of any help, I am rendering on a Canvas. ---编辑---如果有帮助,我将在Canvas上进行渲染。 All I do is call drawColor and draw 3 fairly simple, anti-aliased paths. 我所要做的就是调用drawColor并绘制3条相当简单的抗锯齿路径。 Not really much to it. 没什么大不了的。

PixelFormat shouldn't be a problem. PixelFormat应该不是问题。 You should be even able to set PixelFormat.RGBA_8888 with no performance hiccups. 您甚至应该能够在不影响性能的情况下设置PixelFormat.RGBA_8888。 In some cases this format is useful to reduce color banding on gradients. 在某些情况下,此格式可用于减少渐变上的色带。

Using Handler for animation may be good for simple cases, but you should consider using separate thread for this task. 在简单情况下,使用Handler进行动画处理可能会很好,但是您应该考虑为此任务使用单独的线程。 Some time ago I've prepared simple live wallpaper template . 前段时间,我已经准备了简单的动态壁纸模板 You can download whole project for GitHub and experiment a bit with it. 您可以为GitHub下载整个项目并进行一些试验。 I'm sure that you'll get much better performance. 我相信您会获得更好的性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM