Home > Blockchain >  CGContext addPath to current path
CGContext addPath to current path

Time:02-24

I am confused by addPath() API of CGContextRef. The API documentation says

If the source path is non-empty, then its path elements are appended in order onto the current path. The current transformation matrix (CTM) is applied to the points before adding them to the path. After the call completes, the start point and current point of the path are those of the last subpath in path.

I was thinking that it adds a new subpath to the existing path that is already drawn on the context. But it doesn't seem to behave so. If I were to actually append a subpath to the existing drawn path, how do I achieve it?

CodePudding user response:

If you have already stroked (or filled) the path, there is no current path in this context. The context's current path is cleared as soon as you stroke or fill it.

If I were to actually append a subpath to the existing drawn path, how do I achieve it?

You can't. There is no "drawn path" after you stroke or fill; there are just pixels. You would need to start over with a knowledge of the path that you drew. This is why CGPath and CGMutablePath exist, so that you can save a copy of a path before you draw it, and modify it later.

  • Related