2025-11-16 19:33:01 +08:00

36 lines
1.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//using XPrintServer.TestConsole;
//var runner = new StarVectorRunner("starvector.onnx");
//string svg = runner.GenerateSvg(@"J:\Dev\xprint\public\assets\image\firespace\originpic\test\222.png");
//File.WriteAllText(@"J:\Dev\xprint\public\assets\image\firespace\originpic\test\output.svg", svg);
using XPrint.Image;
using XPrintServer.TestConsole;
try
{
string potracePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"SvgLibs/potrace.exe");
string pngquantPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"SvgLibs/pngquant.exe");
string inputSvgPath = "J:/111.png";
string outputSvgPath = @"F:/output_auto_color.svg";
// 创建位图转SVG转换器实例
var converter = new ColorVectorConverter(potracePath, pngquantPath, false);
// 转换图像保留透明度最多16种颜色
await converter.ConvertToSvg(inputSvgPath, outputSvgPath, 256, 1f, QuantizationAlgorithm.MedianCut, DitheringType.FloydSteinberg, true);
Console.WriteLine($"转换成功SVG文件已保存至: {Path.GetFullPath(outputSvgPath)}");
}
catch (Exception ex)
{
Console.WriteLine($"错误: {ex.Message}");
if (System.Diagnostics.Debugger.IsAttached)
{
Console.WriteLine("按任意键退出...");
Console.ReadKey();
}
}