C# System.IndexAutoFrangeException在itextsharp中添加图像

C# System.IndexAutoFrangeException在itextsharp中添加图像,c#,wpf,itextsharp,C#,Wpf,Itextsharp,我在使用itextsharp将图像添加到pdf时遇到此问题: System.IndexOutOfRangeException: Index was outside the bounds of the array. at System.util.zlib.Tree.d_code(Int32 dist) at System.util.zlib.Deflate.compress_block(Int16[] ltree, Int16[] dtree) 守则: cb.BeginLayer(pdfLay

我在使用itextsharp将图像添加到pdf时遇到此问题:

System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.util.zlib.Tree.d_code(Int32 dist)
at System.util.zlib.Deflate.compress_block(Int16[] ltree, Int16[] dtree)
守则:

 cb.BeginLayer(pdfLayer); 
 iTextSharp.text.Image img = TextSharp.text.Image.GetInstance(memoryStream); 
 img.SetAbsolutePosition(
      (float)(((resBounds.X - rectPage.X) / pageInfo.Dpi * 72.0f) * pageInfo.PrintOptions.Scale), 
      (float)((pageHeight * pageInfo.PrintOptions.Scale) - ((resBounds.Y + resBounds.Height) / pageInfo.Dpi * 72.0f) * pageInfo.PrintOptions.Scale));
 img.ScaleAbsolute((float)((resBounds.Width / pageInfo.Dpi * 72.0f) * pageInfo.PrintOptions.Scale), 
      (float)((resBounds.Height / pageInfo.Dpi * 72.0f) * pageInfo.PrintOptions.Scale)); 
 cb.AddImage(img); 
 cb.EndLayer();
错误发生在以下行中:
cb.AddImage(img)

尝试将流重置回起始位置-我遇到了此问题,并通过以下操作解决了此问题:

memoryStream.Seek(0, SeekOrigin.Begin); //go back to start

与某种形式的光标位置有关-愚蠢但嘿

请提供您的相关代码。请查看。请提供发生异常的代码块。请更新您的问题,而不是在注释中发布代码。此外,如果您能提供一个显示错误的最小且完整的示例程序,这将非常有用。此外,请共享有问题的图像。如果您删除定位和缩放,是否仍会导致异常?