0

All,

Env: .net 2.0, x64 build of Magick.NET library

I have the following code where I read the .tif file and want to convert it to .pdf.

using (MagickImage image = new MagickImage())
        {
            image.SetDefine(MagickFormat.Tiff, "ignore-tags", "32934");
            image.Read(sourceFilePath);;

            image.Write(targetFilePath);
        }

image.Read() throws MagickCoderErrorException, and the inner exception is MagickCoderWarningException complaining about:

ImageMagick.vshost.exe: Unknown field with tag 32934 (0x80a6) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/880

You can clearly see in my code that I instructed the library to ignore this tag and still I get this exception. Why? Btw, when I catch the exception, and do nothing and call image.Write(my.pdf) I get a pdf generated but I don't want to be simply ignoring exceptions if I am doing something wrong.

ActiveX
  • 1,064
  • 1
  • 17
  • 37

2 Answers2

0

It looks like the Error Exception was thrown because the Warning Exception wasn't handled correctly.

Your application should except Warning Exceptions, as this is a common message when working with proprietary, non-compliant, or just odd images.

 try {
   image.Read(sourceFilePath);
 } catch (MagickCoderWarningException err) {
   // Evaluate if this exception will introduce undesired behavior
   // If yes... re-throw 
   throw new Exception('This is undesired', err);
 }
 image.Write(targetFilePath);

Why?

I would highly recommend jumping over to ImageMagick's forums, and discover why this is expected behavior. But don't be put-off, or discourage, if the only response is "That's fine", or "Just ignore that".

emcconville
  • 23,800
  • 4
  • 50
  • 66
  • Your code will not work since the warning exception is an inner exception of the MagickException. I don't know what you mean by this: "It looks like the Error Exception was thrown because the Warning Exception wasn't handled correctly." According to documentation, ignoring specified tags should have silence warning exceptions, which it doesn't. I have added similar code where I catch the root exception, check the inner exception and see if it is warning exception and ignore it but that's expensive when those exceptions occur, ideally you don't exceptions to be thrown. – ActiveX Aug 25 '15 at 00:16
0

All,

This issue was fixed by having the author add support for ignoring tags in the Magic.net library, check release Magick.NET 7.0.0.0018.

ActiveX
  • 1,064
  • 1
  • 17
  • 37