WallpaperService.Engine 的 Android Canvas 多层
我正在制作动态壁纸。壁纸需要小的可移动图像位于具有透明区域的大固定图像后面。较小的图像仅在位于大图像的透明部分时才可见。
到目前为止,我是这样做的:
Canvas c = holder.lockCanvas();
c.save()
drawSmallImages(c); //draw the movable images
drawLargeImage(c); //draw the fixed large image
c.restore();
我通过traceview运行了这个,看起来android正在花费大量的处理能力来绘制大图像,理想情况下我只希望在壁纸时绘制一次开始。我不知道如何在大图像后面绘制较小的图像,而无需在每帧上的较小图像之后重新绘制大图像。
I'm working on a live wallpaper. The wallpaper requires small movable images to be behind a large fixed image with transparent areas. The smaller images will only be visible when they are in the transparent parts of the large image.
Here's how I've been doing it so far:
Canvas c = holder.lockCanvas();
c.save()
drawSmallImages(c); //draw the movable images
drawLargeImage(c); //draw the fixed large image
c.restore();
I ran this through traceview and it looks like android is spending a good chunk of processing power to draw the large image, and ideally I'd only want it to be drawn once when the wallpaper starts. I don't know how to get the smaller images to be drawn behind the larger image without re-drawing the large image after the smaller images on each frame.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
画布的内容不会被清除,因此您可以通过清除小部分并使用剪辑矩形仅重绘大图像的一部分来轻松优化绘图。
The content of the Canvas won't be cleared so you could easily optimize your drawing by clearing small portions and using the clip rect to redraw only part of the large image.