Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top