从C#代码执行Potrace命令,将位图图像转换为XAML
我正在尝试将位图图像转换为XAML格式。目前我正在命令提示符下使用Potrace。我将只通过命令提示符传递输入文件。我的问题是,我必须用C代码做同样的事情。我必须从外部调用Potrace进程并执行它。我尝试了以下代码从C#代码执行Potrace命令,将位图图像转换为XAML,c#,xaml,process,potrace,C#,Xaml,Process,Potrace,我正在尝试将位图图像转换为XAML格式。目前我正在命令提示符下使用Potrace。我将只通过命令提示符传递输入文件。我的问题是,我必须用C代码做同样的事情。我必须从外部调用Potrace进程并执行它。我尝试了以下代码 Process potrace = new Process { StartInfo = new ProcessStartInfo {
Process potrace = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "potrace.exe",
Arguments = "-s -u 1", //SVG
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = Program.IsDebug,
UseShellExecute = false,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
},
EnableRaisingEvents = false
};
StringBuilder svgBuilder = new StringBuilder();
potrace.OutputDataReceived += (object sender2, DataReceivedEventArgs e2) =>
{
svgBuilder.AppendLine(e2.Data);
};
if (Program.IsDebug)
{
potrace.ErrorDataReceived += (object sender2, DataReceivedEventArgs e2) =>
{
Console.WriteLine("Error: " + e2.Data);
};
}
potrace.Start();
potrace.BeginOutputReadLine();
if (Program.IsDebug)
{
potrace.BeginErrorReadLine();
}
BinaryWriter writer = new BinaryWriter(potrace.StandardInput.BaseStream);
Bitmap.Save(writer.BaseStream, ImageFormat.Bmp);
potrace.StandardInput.WriteLine();
potrace.WaitForExit();
这段代码给了我一个错误,编译器说这个内容中不存在程序。!帮我解决这个问题。如果你还有其他建议,我愿意接受 试试这个!注释会禁用某些不起作用的代码部分。 此版本从属性“参数”获取源bmp图像
试试这个!注释会禁用某些不起作用的代码部分。 此版本从属性“参数”获取源bmp图像 只需使用
C#
版本的Potrace
请参阅
基于(Peter Selinger)的C#版本
谁做了这项艰巨的工作
只需使用C#
版本的Potrace
请参阅
基于(Peter Selinger)的C#版本
谁做了这项艰巨的工作
Process potrace = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = @"C:\potrace-1.11.win64\potrace.exe",
Arguments = "C:\\potrace-1.11.win64\\circle.bmp --backend dxf", //DXF
RedirectStandardInput = true,
RedirectStandardOutput = true,
// RedirectStandardError = Program.IsDebug,
UseShellExecute = false,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
},
EnableRaisingEvents = false
};
StringBuilder svgBuilder = new StringBuilder();
potrace.OutputDataReceived += (object sender2, DataReceivedEventArgs e2) =>
{
svgBuilder.AppendLine(e2.Data);
};
/*
if (Program.IsDebug)
{
potrace.ErrorDataReceived += (object sender2, DataReceivedEventArgs e2) =>
{
Console.WriteLine("Error: " + e2.Data);
};
}
*/
potrace.Start();
/*
*
potrace.BeginOutputReadLine();
if (Program.IsDebug)
{
potrace.BeginErrorReadLine();
}
*/
/*
BinaryWriter writer = new BinaryWriter(potrace.StandardInput.BaseStream);
// Construct a new image from the GIF file.
Bitmap bmp2 = new Bitmap(@"C:\Users\Matus\Desktop\potrace-1.11.win64\kruz.bmp");
bmp2.Save(writer.BaseStream, System.Drawing.Imaging.ImageFormat.Bmp);
potrace.StandardInput.WriteLine(); //Without this line the input to Potrace won't go through.
* **/
potrace.WaitForExit();