You're missing a key point of what CGContextReplacePathWithStrokedPath
and CGPathCreateCopyByStrokingPath
do:
The new path is created so that filling it draws the same pixels as stroking the original path.
So, how would you create a fillable path for a line or curve?
Probably something like:
moveto
curveto
(either the outer or the inner curved edge)lineto
(one end)curveto
(either the inner or the outer curved edge)closepath
(the other end)
That closepath
, of course, returns the current point to where step 1 (moveto
) started. That's why that's the result you get.
The original points you started with no longer exist in this path. Indeed, depending on how long your curve is, the dash pattern may mean that no segment overlaps your final point—the last segment may fall short of it.
If you want the start and end of each segment, get the current point before and after lineto
, and take the average, and do the same for the current point before and after closepath
. The two points you get from that are the middle of each straight-line element of the path, which, for a simple curved line segment, will be the start and end of the segment.
I hope your path doesn't have any loops.