我已经让这段代码运行它的作用是流式传输 RDLC 文件,将其转换为图像并保存。流是预先创建的并保存在内存中。我面临的问题是这个功能很慢。执行需要 2-3 秒。执行此行需要大部分时间
graphics.DrawImage(imge, adjustedRect);
最多。我怎样才能让它更快,请帮忙。
public void PrintImagePage(int PageNo)
{
try
{
Metafile imge;
Graphics graphics;
Image pageImage;
PageNo = PageNo - 1;
if (m_streams == null || m_streams.Count == 0)
throw new Exception("Error: no stream to print.");
m_streams[PageNo].Position = 0;
string filePath = _folderPath + _fileNamePrifix + PageNo + ".png";
imge = new Metafile(m_streams[PageNo]);
pageImage = new Bitmap(imge.Width, imge.Height);
graphics = Graphics.FromImage(pageImage);
Rectangle adjustedRect = new Rectangle(
0,
0,
pageImage.Width,
pageImage.Height);
graphics.FillRectangle(Brushes.White, adjustedRect);
// Draw the report content
graphics.DrawImage(imge, adjustedRect);
pageImage = ResizeBitmap(pageImage, .35f, InterpolationMode.HighQualityBicubic);
pageImage.Save(filePath, ImageFormat.Png);
//using (var m = new MemoryStream())
//{
// pageImage.Save(filePath, ImageFormat.Png);
// var img = Image.FromStream(m);
// img.Save(filePath);
// img.Dispose();
//}
imge.Dispose();
graphics.Dispose();
pageImage.Dispose();
}
catch (Exception)
{
throw;
}
}