从位图大纲创建NSBezierPath [英] Create NSBezierPath from bitmap outline

查看:182
本文介绍了从位图大纲创建NSBezierPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个NSBezierPath对象,它对应于任意位图图像的轮廓。

I would like to create a NSBezierPath object which corresponds to the outline of an arbitrary bitmap image.

我的所有图像都是具有透明背景的png纯黑色图形。下面是一个例子:

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?

推荐答案

您正在寻找的是跟踪/向量化算法

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

DrawKit 出现支持位图到向量跟踪

DrawKit appears to support bitmap to vector tracing:

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

一些其他(非ObjC)开源项目实现跟踪(代码引用):

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)

任何曾经使用Illustrator (或任何竞争对手的)跟踪工具可以确保跟踪是一个不平凡的事情,虽然。但对于你的简单b& w图像(技术graysacle,由于抗锯齿,但这是相当可忽略的)在这里任何算法应该做的伎俩。特别是如果你甚至不需要完美的曲线拟合,正如你所说的。

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.

这篇关于从位图大纲创建NSBezierPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆