从位图轮廓创建 NSBezierPath
我想创建一个 NSBezierPath 对象,它对应于任意位图图像的轮廓。
我所有的图像都是带有透明背景的 png 纯色单色形状。这是一个示例:
我想要形状轮廓的贝塞尔曲线路径。实现这一目标的最简单方法是什么?
I would like to create a NSBezierPath object which corresponds to the outline of an arbitrary bitmap image.
All my images are png solid monochrome shapes with transparent backgrounds. Here is an examplee:
I want the bezier path of the outline of the shape. What is the bast way to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在寻找的是跟踪/矢量化算法。
DrawKit 似乎支持位图到矢量跟踪:
一些其他(非 ObjC)实现跟踪的开源项目(用于代码参考):
(ActionScript)
(C++)
(Python)
不过,任何曾经使用过 Illustrator(或其任何竞争对手)跟踪工具的人都可以向您保证,跟踪并不是一件简单的事情。但对于简单的黑白图像(技术上是灰度图像,由于抗锯齿,但这里可以忽略不计),几乎任何算法都应该可以解决问题。特别是如果您甚至不需要完美的曲线拟合,正如您所指出的。
What you are looking for is a tracing/vectorization algorithm.
DrawKit appears to support bitmap to vector tracing:
Some other (non-ObjC) open-source projects implementing tracing (for code reference):
(ActionScript)
(C++)
(Python)
Anyone who has ever used Illustrator's (or any of its competitors') tracing tools can assure you that tracing is a non-trivial thing, though. But for your simple b&w images (technically graysacle, due to antialiasing, but that's rather neglectable here) just about any algorithm should do the trick. Especially if you don't even need perfect curve fitting, as you noted.