/BitmapToVector

C# port of Potrace with optional SkiaSharp support.

Primary LanguageC#GNU General Public License v3.0GPL-3.0

NuGet BitmapToVector

NuGet BitmapToVector.SkiaSharp

BitmapToVector

.NET Standard port of Potrace. In this port, I aim to keep the syntax and comments as close to the C version as possible. This will help with keeping up to date on any new Potrace versions. I only aim to use typical C# syntax in the public API.

Usage:

  1. Install the NuGet package

  2. Write some code:

    // Create PotraceBitmap
    var width = 100;
    var height = 100;
    using var potraceBitmap = PotraceBitmap.Create(width, height);
    
    // Add black pixels
    potraceBitmap.SetBlackUnsafe(0, 0);
    potraceBitmap.SetBlackUnsafe(0, 1);
    
    // Create options
    var param = new PotraceParam();
    
    // Trace using Potrace
    var traceResult = Potrace.Trace(param, potraceBitmap);

    Note: Potrace images are only black and white. If you want to create one from a specific image, you could iterate over the source image's pixels and SetBlackUnsafe wherever you want the Potrace image pixel to be black. BitmapToVector doesn't have features to determine which pixels "should" be black, so that part is up to you.

  3. Refer to Potrace's technical documentation for more information.

BitmapToVector.SkiaSharp

Builds off of BitmapToVector and adds support for SKPath and SKBitmap.

Usage:

  1. Install the NuGet package

  2. Install the SkiaSharp NuGet package

  3. Use these additional methods:

    IEnumerable<SKPath> skPathsFromSKBitmap = PotraceSkiaSharp.Trace(PotraceParam, SKBitmap);
    IEnumerable<SKPath> skPathsFromPotraceBitmap = PotraceSkiaSharp.Trace(PotraceParam, PotraceBitmap);

    Note: PotraceSkiaSharp.Trace will treat all pixels with a red value less than 128 as "black".

Licensing

Please note the GPL-3.0 license. This can have big implications if you decide to use this library.