Each time the image is rendered it is loaded from file, database or other source. So it there is an image that used more than one time in your report, it is loaded in memory again and again.
You could add a hash table to the report that will store the images. Then they will not duplicate in memory. The report is exported to PDF, Word, Excel formats the images are exported just once and there is no duplicated images too.
With our internal format we have other situation. When you save rendered report (mdc or mdx) each image object in stored separately so you get such large file. When this rendered report is loaded you will get separate image in memory for each image component. It's no matter you used Hashtable or not. We have a workaround for this issue. You could add Tag property for each image, then remove images from the rendered report before saving it. But you should add imaged before showing the rendered report.
var report = new StiReport(); report.Load(@"D:\report3.mrt"); report.Render(); //before save foreach (StiPage page in report.RenderedPages) { foreach (StiComponent comp in page.GetComponents()) { var image = comp as StiImage; if ((image != null) && (image.TagValue != null)) { image.ImageToDraw = null; } } } report.SaveDocument(@"d:\report3.mdc"); report.RenderedPages.Clear(); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); Image image1 = Image.FromFile(@"d:\temp\image1.jpg"); Image image2 = Image.FromFile(@"d:\temp\image2.jpg"); Image image3 = Image.FromFile(@"d:\temp\image3.jpg"); report.LoadDocument(@"d:\report3.mdc"); //after load foreach (StiPage page in report.RenderedPages) { foreach (StiComponent comp in page.GetComponents()) { var image = comp as StiImage; if ((image != null) && (image.TagValue != null)) { string tagValue = image.TagValue.ToString(); if (tagValue == "image1") image.ImageToDraw = image1; if (tagValue == "image2") image.ImageToDraw = image2; if (tagValue == "image3") image.ImageToDraw = image3; } } } report.Show();
0 Comments