0

問題のコードは次のとおりです。

MagickNet.InitializeMagick();
ImageMagickNET.Image image = new ImageMagickNET.Image(@"C:\temp.pdf");
image.Quality = 100;
image.CompressType = ImageMagickNET.CompressionType.LosslessJPEGCompression;
image.Write(@"C:\temp.jpg");

このコードが機能するはずだと確信していますが、次の非常に有益な例外が発生します。External component has thrown an exception.

この例外は、次の行でスローされます。ImageMagickNET.Image image = new ImageMagickNET.Image(@"C:\temp.pdf");

内部例外: null

スタックトレース:

   at Magick.Image.{ctor}(Image* , basic_string<char\,std::char_traits<char>\,std::allocator<char> >* )
   at ImageMagickNET.Image..ctor(String imageSpec)
   at WindowsFormsApplication1.Form1.ReadQRCode(String doc) in C:\Users\me\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs:line 126
   at WindowsFormsApplication1.Form1.seperatePDFsInOrder(String fileName) in C:\Users\me\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs:line 109
   at WindowsFormsApplication1.Form1.InitializeComponent() in C:\Users\me\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs:line 44
   at WindowsFormsApplication1.Form1..ctor() in C:\Users\me\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs:line 16
   at WindowsFormsApplication1.Program.Main() in C:\Users\me\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:line 20
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

私が間違って何をしているのか誰にも分かりますか?

4

1 に答える 1

2

2番目の引用行で* .pdfimage = newファイルとして宣言しているようです。で試してみるとよいでしょう。またはさらに良い...c:\tmp.jpgc:\temp\tmp.jpg

ImageMagick は、接尾辞 *.pdf がある場合、「このファイルを PDF として解析したい」モードを適用します。(ファイル名に接尾辞がない場合にのみ、魔法のファイル タイプ検出ルーチンが適用されます。)

また、コードを実行しているユーザーがファイルを書き込めない可能性がありますc:\tmp.jpg。次の 2 つの理由が考えられます。

  1. c:\ ディレクトリとして、このユーザーは書き込み可能ではありません。
  2. ファイルは既に存在し、このユーザーが上書きすることはできません (別のユーザーに属している可能性があります)。

最後に、PDF を入力として処理する ImageMagick の機能は、外部の「デリゲート」に依存していることに注意してください。それ自体はそのジョブを実行できず、同じホストに Ghostscript をインストールして呼び出してジョブを実行させる必要があります...

于 2012-07-07T09:03:15.937 に答える