在保存png到内存流时,我遇到了错误。在我的ASP.NET开发服务器上一切正常,但是当我在IIS7下运行网站时,就会生成错误。同时,当我尝试保存jpg格式时,一切都正常。在IIS中,我已将.NET受信任级别设置为完全。但它仍然无法正常工作。我需要你的帮助。
private static Stream DrawBarChart(IEnumerable<Tuple<string, ulong, double>> data){
using (MemoryStream stream = new MemoryStream())
{
var canvasWidth = PageSize.A4.Width;
var canvasHeight = PageSize.A4.Height;
using (
System.Drawing.Image bitmap = new Bitmap((int) canvasWidth,
(int) canvasHeight))
{
using (var graphics = Graphics.FromImage(bitmap))
{
var penBlack1 = new Pen(Brushes.Black, 1);
graphics.DrawLine(penBlack1, 0, 0, canvasWidth, 0);
graphics.DrawLine(penBlack1, 0, 0, 0, canvasHeight);
graphics.Save();
}
bitmap.Save(stream, ImageFormat.Png);
stream.Flush();
stream.Position = 0;
return stream;
}
}
}