In Apple docs they give you code of how to convert NSBezierPath to CGPathRef. I need to convert the other way around, from CGPathRef to NSBezierPath. UIBezierPath has a property called cgPath so if I was working on iPhone that would not be a problem, but I'm working on MacOS.
This must be an old question, and I was sure to find an answer on Internet but no luck. Could be I'm missing something. Any help appreciated.
Old question but I'm sure this will still be helpful for others. (You didn't specify Objective-C or Swift; this is an Objective-C answer.)
You can convert a
CGPathRef
to anNSBezierPath
usingCGPathApply()
with an applier function callback that translates theCGPathRef
points toNSBezierPath
points. The only tricky part is the conversion fromCGPathRef
's quadratic curves toNSBezierPath
's cubic curves but there's an equation for that:Using the equation above, here's an
NSBezierPath
category for converting fromCGPathRef
:NSBezierPath+BezierPathWithCGPath.h
NSBezierPath+BezierPathWithCGPath.m
Called like so: