将2页.tiff文件转换为.jpg

时间:2014-03-14 09:26:08

标签: c# imagemagick c#-2.0 magick.net

转换/读取2页.tif文件时出错。什么是正确的方法?

2 page

这是错误:

ImageMagick.MagickCoderErrorException: Magick: C:\DigitalAssets\sample.TIF: Null count for "Tag 33426" (type 4, writecount -3, passcount 1). `_TIFFVSetField' @ error/tiff.c/TIFFErrors/561
   at ImageMagick.MagickImage.HandleReadException(MagickException exception)
   at ImageMagick.MagickImage.Read(String fileName, MagickReadSettings readSettings)
   at Digital_Asset_Converter_Service.Service.EPSFolderWatcher_Created(Object sender, FileSystemEventArgs e)

以下是代码:

string fileName = @"C:\DigitalAssets\sample.tif";
using (MagickImageCollection image = new MagickImageCollection())
    {
        MagickReadSettings settings = new MagickReadSettings();
        // settings.ColorSpace = ColorSpace.RGB;
        settings.Density = new MagickGeometry(300, 300);
        //settings.FrameIndex = 0;
        // settings.FrameCount = 1;

        image.Read(fileName,settings);
    }

1 个答案:

答案 0 :(得分:1)

您的图片包含一个损坏的tiff标记,该标记会导致MagickCoderErrorException。我们对ImageMagick进行了更改,允许您忽略特定的tiff标记。下面是一个阻止MagickCoderErrorException的示例:

using (MagickImage image = new MagickImage())
{
  image.SetDefine(MagickFormat.Tiff, "ignore-tags", "33426");
  // Or if you want to ignore multiple tags:
  image.SetDefine(MagickFormat.Tiff, "ignore-tags", "33426,33428");

  MagickReadSettings settings = new MagickReadSettings();
  // settings.ColorSpace = ColorSpace.RGB;
  settings.Density = new MagickGeometry(300, 300);

  image.Read(fileName, settings);
}