About 2 weeks ago I saw a post from senocular on the actionscript.org forums. In it, he was replying to a user who was asking if you could do Trace Bitmap at runtime. Of course, you can’t do that, and senocular said that as far as he knew he hadn’t seen a class that did it.
So, being the masochist I am, I decided to take up the challenge. 2 weeks of spare time later and I now have the Vectorization Package. It’s three classes written in AS3 for Flash Player 9 and up. I gotta say, it was a really fun exercise in using the tools available to do something new.
Check out the example and feel free to play around. Unlike Trace Bitmap, you can get results that will have gaps between shapes if you kick up the curve smoothness setting. I felt this was acceptable mainly because I liked some of the abstract results that would come from it. Plus it saves me from having to write yet another crazy intensive routine.
Accessors include:
[LIST]
[]**threshold **- Just like Trace Bitmap, this is the color threshold used to determine the range of acceptable colors when grouping shapes.
[]**minimumArea **- Lets you limit the smallest-sized shape allowed, by number of pixels.
[]**curveSmoothness **- Controls how curvy shapes can be drawn. This ties into the next property…
[]**stepSize **- As each final vector shape is drawn, stepSize controls how many pixels the package moves along the edge before evaluating whether or not it needs to draw the next part of the outline (that evaluation compares the angle of change to the value provided in curveSmoothness). So, as you increase curveSmoothness, you’ll also want to increase stepSize a little to help keep your curves large and bold.
[*]**transparentColor **- For a lot of good reasons I’m not going to get into, this package does not support transparency in the final vector image. The transparentColor property lets you choose what color will go in place of any transparent areas in your original raster image.
[/LIST]
The Vectorization Package works with all DisplayObjects. So even through they’re already vector, you could re-vectorize things like Shapes and Textfields (makes for fun results). You can even do an FLV (it would vectorize whatever frame was up when you run it).
In the process of making this, I had to write a despeckle/posterize routine and a find edges routine. They work so nicely that I plan on making them their own classes and releasing them as well.
The Vectorization Package is released under the MIT license. As it is with any code I release, I encourage you to let me know if you use it for anything! I always like to know when my code can help someone out.
-----> VECTORIZATION PACKAGE - DOWNLOAD AND DOCS <------
I’d love feedback on it! I really don’t know if anyone’s done this before, so kinda neat to think I might be the first. And if I’m not, I’m still pretty darn happy with how this turned out. Not sure if there’s much use for this, but I’ve seen it requested enough times over the years that at least now people can stop asking.
And if you happen to read this senocular, thanks for inadvertantly sprouting the idea in my head!