努力清除 CGLayer 中的所有数据——这能做到吗?

发布于 2024-10-10 10:15:41 字数 777 浏览 6 评论 0原文

我们不断地制作一个CGLayer,进行处理,然后发布它。这种情况实时发生很多次。当然,每次制作一个全新的 CGLayer 都会产生大量的开销。所以......

当然,最好保留该图层,并每次删除其中的所有数据 - 而不是从头开始创建一个新图层。

注意:如果您在覆盖所有内容的空白或透明矩形中进行绘制,只会在现有路径之上添加更多数据

那么,如何真正“擦除”或“重新开始”CGLayer?

有一个函数 CGContextBeginPath(cc) 但它令人困惑:它似乎只清除“那个”路径,它似乎不会将所有 CGLayer 擦除回无数据状态< /em>。

如何将 CGLayer 返回到无数据状态?有谁知道吗?

更新...

事实证明实际上没有办法做到这一点。

经过大量的实验,我们发现似乎没有办法清除 CGLayer 中的所有数据(这确实令人失望)。

请注意,添加新的白色或透明矩形仅能做到这一点 - 它实际上会添加更多数据。

不幸的是,没有已知的方法可以做到这一点。如果您在高赫兹下构建这些(可能是为了计算),您只需每次都从一个新的开始。或者,您可以使用 CGContextBeginPath() 显然删除(实际上是删除,而不仅仅是覆盖)仅一个路径。

希望这对将来的人有所帮助。

We're repetitively making a CGLayer, doing processing, and then releasing it. This happens a lot in real time. Surely there is a lot of overhead in making a whole new CGLayer each time. So...

Surely it would be better to just keep the layer around, and erase all the data from it each time -- rather than creating a new one from scratch.

Note: if you paint in a blank or clear rectangle covering everything, that just adds even more data on top of your extant paths.

So, how to actually "erase" or "start again" a CGLayer?

There is a function CGContextBeginPath(cc) but it's confusing: it seems to only clear out "that" path, it does not appear to erase all of the CGLayer back to no-data state.

How to return a CGLayer to a state of no-data? Does anyone know?

Update...

It turns out there is actually NO WAY TO DO THIS.

After considerable experimentation, we have determined that there appears to be no way to clear out all the data from a CGLayer (which is disappointing really).

Note that adding a new white or clear rectangle, only does that - it actually adds more data.

So unfortunately no known way to do this. If you are building these at high hz (perhaps for a calculation), you just have to start with a fresh one each time. Or, you can apparently delete (actually delete, not just cover) just the one path using CGContextBeginPath().

Hopefully this will help someone in the future.

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

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

发布评论

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

评论(2

把人绕傻吧 2024-10-17 10:15:41

获得上下文后,调用 CGContextClearRect( cc, someRect ) 来清除内容。

Once you have the context call CGContextClearRect( cc, someRect ) to clear the contents.

少女净妖师 2024-10-17 10:15:41

为什么不直接用(透明/白色)颜色的矩形填充它呢?
如果您想使用clearColor(透明)清除图层,请确保该图层不是不透明的。

Why don't you just fill it with a rectangle of (clear/white) color?
Make sure the layer is not opaque if you wanna clear it with clearColor (transparent).

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