我有一种延迟方法,根据流大小引发异常。我有一种感觉,问题是内存限制。有人能解释我为什么会得到这些错误以及如何解决这个问题?
private List<MemoryStream> streams = new List<MemoryStream>();
private byte[] GetReportImage(IReportDocument report, bool portrait)
{
var processor = new ReportProcessor();
var reportSource = new InstanceReportSource();
reportSource.ReportDocument = report;
var deviceInfo = new System.Collections.Hashtable();
deviceInfo["OutputFormat"] = "PNG";
deviceInfo["DpiX"] = portrait ? imagePortraitDpi : imageLandscapeDpi;
deviceInfo["DpiY"] = portrait ? imagePortraitDpi : imageLandscapeDpi;
string documentName = "";
this.streams.Clear();
MemoryStream resultStream;
try
{
var result = processor.RenderReport("IMAGE", reportSource, deviceInfo, new CreateStream(CreateStream), out documentName);
var width = portrait ? widthPortait : widthLandscape;
var height = portrait ? heightPortrait : heightLandscape;
using (resultStream = new MemoryStream())
{
using (var resultBitmap = new Bitmap(width, height * streams.Count)) <- here parameter is not valid c#
{
using (var graphics = Graphics.FromImage(resultBitmap))
{
int offsetY = 0;
foreach (var stream in this.streams)
{
graphics.DrawImage(Image.FromStream(stream), 0, offsetY, width, height);
offsetY += height;
graphics.Save();
}
}
resultBitmap.Save(resultStream, System.Drawing.Imaging.ImageFormat.Png); <-- here A generic error occurred in GDI+.
}
}
}
finally
{
foreach (var stream in this.streams)
stream.Close();
}
return resultStream.ToArray();
}
宽度= 994; 身高= 703;
当streams.Count = 90和streams.Sum(p =&gt; p.Length)= 1261524时 - 没有抛出任何异常,一切正常。 当streams.Count = 96和streams.Sum(p =&gt; p.Length)= 1342111时 - GDI +中发生一般错误。 当streams.Count = 119和streams.Sum(p =&gt; p.Length)= 1556359 - 参数无效