2

当我在 Windows 中打开命令窗口并使用 imagemagick convert 命令时:

转换 /somedir/Garden.jpg /somedir/Garden.png

它按预期工作。

我想要做的是使用 C# 执行与上面相同的命令。

我尝试使用 System.Diagnostics.Process,但是没有创建 foo.png。

我正在使用这段代码:

      var proc = new Process
      {
          StartInfo =
          {
              Arguments = string.Format("{0}Garden.jpg {1}Garden.png",
              TEST_FILE_DIR,
              TEST_FILE_DIR),
              FileName = @"C:\xampp\ImageMagick-6.5.4-Q16\convert",
              UseShellExecute = false,
              CreateNoWindow = true,
              RedirectStandardOutput = false,
              RedirectStandardError = false
          }
      };

      proc.Start();

不会抛出异常,但也不会写入 .png。

4

1 回答 1

6

我的猜测是它TEST_FILE_DIR包含一个空格 - 所以你必须引用它。

试试这个:

Arguments = string.Format("\"{0}Garden.jpg\" \"{1}Garden.png\"",
                          TEST_FILE_DIR,
                          TEST_FILE_DIR)

您可能还想提供包含扩展名的文件名,例如

FileName = @"C:\xampp\ImageMagick-6.5.4-Q16\convert.exe"
于 2009-09-13T07:17:18.587 回答