EDN Admin
Well-known member
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<br/>
Bitmap multi = null;<br/>
ImageCodecInfo myImageCodecInfo;<br/>
System.Drawing.Imaging.Encoder myEncoder;<br/>
EncoderParameter myEncoderParameter;<br/>
EncoderParameter CompressionEncoderParameter;<br/>
EncoderParameters myEncoderParameters;<br/>
System.Drawing.Imaging.Encoder encoderCompression = System.Drawing.Imaging.Encoder.Compression;<br/>
<br/>
// Get an ImageCodecInfo object that represents the TIFF codec.<br/>
myImageCodecInfo = GetEncoderInfo("image/tiff");<br/>
// Create an Encoder object based on the GUID<br/>
// for the SaveFlag parameter category.<br/>
myEncoder = System.Drawing.Imaging.Encoder.SaveFlag;<br/>
// Create an EncoderParameters object.<br/>
// An EncoderParameters object has an array of EncoderParameter<br/>
// objects. In this case, there is only one<br/>
// EncoderParameter object in the array.<br/>
myEncoderParameters = new EncoderParameters(2);
while (enumerator.MoveNext())<br/>
{<br/>
//For mapping Image indices with Defect Id<br/>
List<DefectImage> defImgList = new List<DefectImage>();<br/>
<span style="white-spacere IEnumerable<ImageClip> imgClipList = enumerator.Current.Value;<br/>
foreach (ImageClip imgClip in imgClipList)<br/>
{<br/>
Bitmap bmp = imgClip.Image;<br/>
if (validCount == 1) // for the first image.<br/>
{<br/>
multi = new Bitmap((Image)bmp);<br/>
myEncoderParameter = new EncoderParameter(myEncoder, (long)(EncoderValue.MultiFrame));<br/>
CompressionEncoderParameter = new EncoderParameter(encoderCompression, (long)(EncoderValue.CompressionNone));<br/>
myEncoderParameters.Param[0] = myEncoderParameter;<br/>
myEncoderParameters.Param[1] = CompressionEncoderParameter;<br/>
multi.Save(fileName, myImageCodecInfo, myEncoderParameters);<br/>
}<br/>
else<br/>
{<br/>
myEncoderParameter = new EncoderParameter(myEncoder, (long)(EncoderValue.FrameDimensionPage));<br/>
CompressionEncoderParameter = new EncoderParameter(encoderCompression, (long)(EncoderValue.CompressionNone));<br/>
myEncoderParameters.Param[0] = myEncoderParameter;<br/>
myEncoderParameters.Param[1] = CompressionEncoderParameter;<br/>
multi.SaveAdd(bmp, myEncoderParameters);<br/>
}<br/>
bmp.Dispose();<br/>
}<br/>
}
<
Satya...
<br/>
View the full article
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<br/>
Bitmap multi = null;<br/>
ImageCodecInfo myImageCodecInfo;<br/>
System.Drawing.Imaging.Encoder myEncoder;<br/>
EncoderParameter myEncoderParameter;<br/>
EncoderParameter CompressionEncoderParameter;<br/>
EncoderParameters myEncoderParameters;<br/>
System.Drawing.Imaging.Encoder encoderCompression = System.Drawing.Imaging.Encoder.Compression;<br/>
<br/>
// Get an ImageCodecInfo object that represents the TIFF codec.<br/>
myImageCodecInfo = GetEncoderInfo("image/tiff");<br/>
// Create an Encoder object based on the GUID<br/>
// for the SaveFlag parameter category.<br/>
myEncoder = System.Drawing.Imaging.Encoder.SaveFlag;<br/>
// Create an EncoderParameters object.<br/>
// An EncoderParameters object has an array of EncoderParameter<br/>
// objects. In this case, there is only one<br/>
// EncoderParameter object in the array.<br/>
myEncoderParameters = new EncoderParameters(2);
while (enumerator.MoveNext())<br/>
{<br/>
//For mapping Image indices with Defect Id<br/>
List<DefectImage> defImgList = new List<DefectImage>();<br/>
<span style="white-spacere IEnumerable<ImageClip> imgClipList = enumerator.Current.Value;<br/>
foreach (ImageClip imgClip in imgClipList)<br/>
{<br/>
Bitmap bmp = imgClip.Image;<br/>
if (validCount == 1) // for the first image.<br/>
{<br/>
multi = new Bitmap((Image)bmp);<br/>
myEncoderParameter = new EncoderParameter(myEncoder, (long)(EncoderValue.MultiFrame));<br/>
CompressionEncoderParameter = new EncoderParameter(encoderCompression, (long)(EncoderValue.CompressionNone));<br/>
myEncoderParameters.Param[0] = myEncoderParameter;<br/>
myEncoderParameters.Param[1] = CompressionEncoderParameter;<br/>
multi.Save(fileName, myImageCodecInfo, myEncoderParameters);<br/>
}<br/>
else<br/>
{<br/>
myEncoderParameter = new EncoderParameter(myEncoder, (long)(EncoderValue.FrameDimensionPage));<br/>
CompressionEncoderParameter = new EncoderParameter(encoderCompression, (long)(EncoderValue.CompressionNone));<br/>
myEncoderParameters.Param[0] = myEncoderParameter;<br/>
myEncoderParameters.Param[1] = CompressionEncoderParameter;<br/>
multi.SaveAdd(bmp, myEncoderParameters);<br/>
}<br/>
bmp.Dispose();<br/>
}<br/>
}
<
Satya...
<br/>
View the full article