WallpaperService.Engine 的 Android Canvas 多层

发布于 2024-10-05 15:52:58 字数 380 浏览 0 评论 0原文

我正在制作动态壁纸。壁纸需要小的可移动图像位于具有透明区域的大固定图像后面。较小的图像仅在位于大图像的透明部分时才可见。

到目前为止,我是这样做的:

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 技术交流群。

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

发布评论

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

评论(1

醉梦枕江山 2024-10-12 15:53:03

画布的内容不会被清除,因此您可以通过清除小部分并使用剪辑矩形仅重绘大图像的一部分来轻松优化绘图。

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.

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