Question

I have such code

using (Image image = System.Drawing.Image.FromStream(sourceStream))
{
    Guid objGuid = image.FrameDimensionsList[0];
    FrameDimension objDimension = new FrameDimension(objGuid);
    int pageCount = image.GetFrameCount(objDimension);

    for (int i = 0; i < pageCount; i++)
    {
          image.SelectActiveFrame(objDimension, i);
          resultStream = new MemoryStream();
          image.Save(resultStream, ToSystemImageFormat(outputFormat));
          result.Add(resultStream.ToArray());
    }
}

the purpose - to save each TIFF's page as png and store it as byte's array. The problem that on my two WIN7 computers that I tested it works fine. But I have one WinXP computer and this piece of code fails with "Parameter not valid" exception. The TIFF document always the same. Somebody knows where is the problem?

I tried to use ImageConverter:

ImageConverter imageConverter = new System.Drawing.ImageConverter();
using (Image image = (Image)imageConverter.ConvertFrom(sourceContent))
{
     Guid objGuid = image.FrameDimensionsList[0];
     FrameDimension objDimension = new FrameDimension(objGuid);
     int pageCount = image.GetFrameCount(objDimension);

     for (int i = 0; i < pageCount; i++)
     {
            image.SelectActiveFrame(objDimension, i);
            resultStream = new MemoryStream();
            image.Save(resultStream, ToSystemImageFormat(outputFormat));
            result.Add(resultStream.ToArray());
      }
}

but it fails too with same exception. Thank you

UPD#1: It fails on Image.FromStream() method. I forgot to mention that the most TIFF documents are converted without any problem, it fails on specific ones. But on WIN7 verything fine even with these specific ones.

Was it helpful?

Solution

I know that winxp has limited support for png. You can't load icon files that are actually compressed pngs (the standard on win 7) in .net 4.0 running on winxp, you get the same exception.

OTHER TIPS

I recommend trying LibTiff.Net. Alternately, you could go with libtiff (C++ code), but I suspect LibTiff.Net will be easier to call from your .Net code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top