Create NSBezierPath from bitmap outline

核能气质少年 提交于 2019-12-07 06:05:48

问题


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?


回答1:


What you are looking for is a tracing/vectorization algorithm.

DrawKit appears to support bitmap to vector tracing:

  • DKImageShape+Vectorization.m
  • NSImage+Tracing.m

Some other (non-ObjC) open-source projects implementing tracing (for code reference):

  • http://code.google.com/p/vectorizationpackage/ (ActionScript)
  • http://code.google.com/p/linetracer/ (C++)
  • http://code.google.com/p/vector/ (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.



来源:https://stackoverflow.com/questions/5259268/create-nsbezierpath-from-bitmap-outline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!