首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从C#代码中执行Potrace命令,将位图图像转换为XAML

从C#代码中执行Potrace命令,将位图图像转换为XAML
EN

Stack Overflow用户
提问于 2013-11-19 13:28:24
回答 2查看 1.2K关注 0票数 1

我正在尝试将我的位图图像转换为XAML格式。目前,我在命令提示符下使用Potrace。我将只通过命令提示符传递输入文件。我的问题是,我必须使用C#代码来做同样的事情。我必须在外部调用Potrace进程并执行它。我尝试了以下代码

代码语言:javascript
复制
               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();

这段代码给了我一个错误,编译器说Program不存在于此内容中。帮我解决这个问题。如果你有任何其他建议,我很乐意接受。

EN

回答 2

Stack Overflow用户

发布于 2018-10-15 03:03:45

只需使用PotraceC#版本即可,参见here

C#版的http://potrace.sourceforge.net/ (彼得·塞林格)基于http://www.drawing3d.de/完成了艰难的工作。

票数 1
EN

Stack Overflow用户

发布于 2014-07-04 22:27:33

尝尝这个!某些不起作用的代码部分会被注释禁用。此版本从属性"Arguments“获取源bmp图像。

代码语言:javascript
复制
        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();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20063883

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档