I have got this code running what it does is stream an RDLC file, converts it to image and saves it. The stream is created before hand and kept in the memory. The Problem i am facing is this function is very slow. It take 2-3 sec to execute. It takes most time to execute this line
graphics.DrawImage(imge, adjustedRect);
most. How can I make it faster please help.
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;
}
}