我无法弄清楚我需要在哪里放置ImageMagick文件来处理它们。我试图在我的ASP.NET MVC网站中使用它,并且没有运气让它找到我要处理的文件。如果确实如此,我如何指定它们的输出位置?
我一直在这里看,我错过了一些东西: http://www.imagemagick.org/script/command-line-processing.php
以下是我调用该流程的代码:
//Location of the ImageMagick applications
private const string pathImageMagick = @"C:\Program Files\ImageMagick-6.7.3-8";
private const string appImageMagick = "MagickCMD.exe";
CallImageMagick("convert -density 400 SampleCtalog.pdf -scale 2000x1000 hi-res%d.jpg");
private static string CallImageMagick(string fileArgs)
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
Arguments = fileArgs,
WorkingDirectory = pathImageMagick,
FileName = appImageMagick,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true
};
using (Process exeProcess = Process.Start(startInfo))
{
string IMResponse = exeProcess.StandardOutput.ReadToEnd();
exeProcess.WaitForExit();
exeProcess.Close();
return !String.IsNullOrEmpty(IMResponse) ? IMResponse : "True";
}
}
答案 0 :(得分:1)
我们做了类似的事情,但是使用环境变量(这是有利的,因为它适用于每个系统)来执行我们使用convert和参数提供的cmd.exe。这就是我们创建ProcessStartInfo对象的方式:
// Your command
string command = "convert...";
ProcessStartInfo procStartInfo = new ProcessStartInfo {CreateNoWindow = true};
string fileName = Environment.GetEnvironmentVariable("ComSpec");
if (String.IsNullOrEmpty(fileName))
{
// The "ComSpec" environment variable is not present
fileName = Environment.GetEnvironmentVariable("SystemRoot");
if (!String.IsNullOrEmpty(fileName))
{
// Try "%SystemRoot%\system32\cmd.exe"
fileName = Path.Combine(Path.Combine(fileName, "system32"), "cmd.exe");
}
if ((String.IsNullOrEmpty(fileName)) || (!File.Exists(fileName)))
{
// If the comd.exe is not present, let Windows try to find it
fileName = "cmd";
}
}
procStartInfo.FileName = fileName;
procStartInfo.RedirectStandardInput = true;
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
Process proc = Process.Start(procStartInfo);
proc.StandardInput.WriteLine(command);
proc.StandardInput.Flush();
然后我们从proc.StandardOutput读取以获取错误消息和结果代码。之后,我们会销毁这些物品。
很抱歉,如果这不是100%,我会从更复杂的OO代码中复制它。