Problem with creating more than 2GB TIFF file using Image.SaveAdd .Net 4.0

  • Thread starter Thread starter spuvvada
  • Start date Start date
S

spuvvada

Guest
Hi,

I am creating an TIFF in C#.Net as written below. At one point of time when the TIFF file reaches to 2GB, it is throwing the following exception (Windows Server 2003 R2, X64 SP2).

Can Someone help me on this?

System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. at System.Drawing.Image.SaveAdd(Image image, EncoderParameters encoderParams)

Code:

// Saving the combined tiff file based on FCL classes
Bitmap multi = null;
ImageCodecInfo myImageCodecInfo;
System.Drawing.Imaging.Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameter CompressionEncoderParameter;
EncoderParameters myEncoderParameters;
System.Drawing.Imaging.Encoder encoderCompression = System.Drawing.Imaging.Encoder.Compression;

// Get an ImageCodecInfo object that represents the TIFF codec.
myImageCodecInfo = GetEncoderInfo("image/tiff");
// Create an Encoder object based on the GUID
// for the SaveFlag parameter category.
myEncoder = System.Drawing.Imaging.Encoder.SaveFlag;
// Create an EncoderParameters object.
// An EncoderParameters object has an array of EncoderParameter
// objects. In this case, there is only one
// EncoderParameter object in the array.
myEncoderParameters = new EncoderParameters(2);

while (enumerator.MoveNext())
{
//For mapping Image indices with Defect Id
List<DefectImage> defImgList = new List<DefectImage>();
IEnumerable<ImageClip> imgClipList = enumerator.Current.Value;
foreach (ImageClip imgClip in imgClipList)
{
Bitmap bmp = imgClip.Image;
if (validCount == 1) // for the first image.
{
multi = new Bitmap((Image)bmp);
myEncoderParameter = new EncoderParameter(myEncoder, (long)(EncoderValue.MultiFrame));
CompressionEncoderParameter = new EncoderParameter(encoderCompression, (long)(EncoderValue.CompressionNone));
myEncoderParameters.Param[0] = myEncoderParameter;
myEncoderParameters.Param[1] = CompressionEncoderParameter;
multi.Save(fileName, myImageCodecInfo, myEncoderParameters);
}
else
{
myEncoderParameter = new EncoderParameter(myEncoder, (long)(EncoderValue.FrameDimensionPage));
CompressionEncoderParameter = new EncoderParameter(encoderCompression, (long)(EncoderValue.CompressionNone));
myEncoderParameters.Param[0] = myEncoderParameter;
myEncoderParameters.Param[1] = CompressionEncoderParameter;
multi.SaveAdd(bmp, myEncoderParameters);
}
bmp.Dispose();
}
}
Satya...

Continue reading...
 
Back
Top