IM on CMD WORKS but not .NET program

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
hoanghuynh
Posts: 2
Joined: 2018-01-09T20:05:27-07:00
Authentication code: 1152

IM on CMD WORKS but not .NET program

Post by hoanghuynh » 2018-01-11T00:09:33-07:00

Hi,
i'm tring to convert a .tiff image to .pdf, using IM 6.9.9-Q16 on Win Server 2012 R2 64bit by this command:
CODE: SELECT ALL

convert -resample 200x200 pathTIFFfile pathPDFfile
if i run this command on CMD works fine, it generate a pdf file and i can open it.
but if i try to develop same thing on .NET using this command:

CODE: SELECT ALL

public string modifyResolution(String fileName, string resolution, string imageName, Logger serviceLogger)
{


string converterPath = ConfigurationSettings.AppSettings["ResampleToolPath"];
string resampleDir = ConfigurationSettings.AppSettings["ResampleDir"];
string convertedPdf = resampleDir + imageName + ".pdf";


try
{

ProcessStartInfo pinfo = new ProcessStartInfo();
pinfo.UseShellExecute = true;
pinfo.RedirectStandardOutput = false;
pinfo.CreateNoWindow = true;
pinfo.FileName = converterPath;

pinfo.Arguments = "convert -resample " + resolution + "x" + resolution + " " + fileName + " " + convertedPdf;


Process proc = null;
try
{
proc = Process.Start(pinfo);
proc.WaitForExit();
}
catch (Exception ex)
{

serviceLogger.WriteMessage("PROCESS EXCEPTION", ex.Message + " | " + ex.StackTrace + " | " +ex.Source );
}

}
catch (Exception ex)
{
serviceLogger.WriteMessage("ERR", ex.Message + "/" + ex.InnerException.Message + "/" + ex.StackTrace);
return ex.Message + "/" + ex.InnerException.Message + "/" + ex.StackTrace;
}

return convertedPdf;

}
it doesn't work, not create a file pdf, anyone can help me?

Thanks,

snibgo
Posts: 10281
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM on CMD WORKS but not .NET program

Post by snibgo » 2018-01-11T02:40:32-07:00

What error message does IM send to stdout?
snibgo's IM pages: im.snibgo.com

jmaeding
Posts: 51
Joined: 2006-05-03T09:48:26-07:00

Re: IM on CMD WORKS but not .NET program

Post by jmaeding » 2018-01-11T09:52:10-07:00

I use .net with IM for many things, and run it through the ole object (com) like:
ImageMagickObject.MagickImage img = new ImageMagickObject.MagickImage();
object ret1 = img.Convert(argsall.ToArray());

where argsall is an array of strings which are the parameters.
You need to add the ImageMagickObject as a reference.
James Maeding
Civil Engineer / Programmer

Post Reply