Very large WinForm Diagram - ExportDiagramAsImage overflow

We are using your Diagram Control (WinForms) to produce database diagrams for large number of tables and their field-to-field connections.   It is not unusual to have in excess of 200 tables, and several thousand connections on a diagram.    This does work just fine, both the diagram window and the overview window can handle this requirement.

However, we would also like to save these diagrams as: Image, Word and PDF Documents.   We totally get it that both the Word and PDF documents will need to contain multiple pages that contain a portion of the overall diagram.

 Our issue is with the ExportDiagramAsImage method.   We are quite certain that the issue is a memory overflow.    The ExportDiagramAsImage always returns an "Invalid Parameter" error.

A diagram may be 16,063 pixels wide by 42,883 pixels high - according to the bounds of the diagram object.
At full color, this translates into about 5GB of memory ( 6 * 16053 * 42883).

We totally get it that this is simply too large, and you are not in control of memory management.

Our question is:  Is there some approach to perhaps capturing a "moving window" to reduce the memory requirements.   We certainly know the native size of the diagram and could easily walk that using smaller windows, but we have been unable to locate a method in the Diagram class that accepts any "boundary rectangle" that could be converted to an image.

Thoughts?

5 Replies 1 reply marked as answer

NG Naganathan Ganesh Babu Syncfusion Team February 11, 2021 02:40 PM UTC

Hi Mark, 
 
We have created a simple sample to export the diagram as image as user defined bounds. Please refer to the below code example and sample. 
 
Code example: 
 
[C#] 
   
private void saveImageToolStripMenuItem_Click(object sender, EventArgs e) 
        { 
            Graphics gfx; 
            //Here I have get the diagram content bounds only to export the diagram as an image... 
            //You can modify the bounds value to export the diagram as per your requirement... 
            RectangleF rectBounding = this.diagram1.Controller.GetBoundingRect(diagram1.Model.Nodes, MeasureUnits.Pixel); 
 
            Bitmap img = new Bitmap((int)(rectBounding.Size.Width), (int)(rectBounding.Size.Height)); 
            gfx = Graphics.FromImage(img); 
            this.diagram1.ExportDiagramToGraphics(gfx, rectBounding); 
 
            gfx.DrawImage(img, rectBounding); 
            using (Bitmap newBitmap = new Bitmap(img, (int)(rectBounding.Size.Width), (int)(rectBounding.Size.Height))) 
            { 
                newBitmap.Save("..//..//file300.jpg", ImageFormat.Bmp); 
            } 
        } 
 
 
Regards, 
 
Naganathan K G 



MT Mark T Lochiano February 11, 2021 10:40 PM UTC

Thank you for the example....however it does not address the fundamental constraint of supporting an image that is 16,000 by 42,000 pixels since it grabs the entire image at once.

We have worked out a sliding window approach.  It walks the entire diagram capturing portions of the image.   Each image is 642x864 pixels (approx. 1 page width)
However, right now there is a fatal flaw.   The first two screen grabs working perfectly.   Unfortunately after that all subsequent captures are pure white.

  In attempting to see if this might be because those areas were off screen, we auto scrolled through the entire diagram to make sure that the area we grabbed was visible on the screen.   The scrolling works great....but no change to the 'all white' results.

here is what we have at this point --- this method is in a child dialog of the overall diagram, and is passed the diagram object along with a capture file naming prefix.  Please see if we are missing some fundamental concept.



Attachment: Currrent_Capture_Method_df4c2fe7.zip


GG Gowtham Gunashekar Syncfusion Team February 12, 2021 03:30 PM UTC

Hi Mark,  
 
We are validating your requirements and update you with more details on February 16th   2021. 
 
Regards,  
Gowtham   
 



MT Mark T Lochiano February 12, 2021 06:18 PM UTC

Understand.   Thank you for your support.


NG Naganathan Ganesh Babu Syncfusion Team February 15, 2021 09:14 AM UTC

Hi Mark 
 
Already we have an online KB documentation for exporting the diagram as PDF in multiple page. You can use same code example to export the diagram as multiple image. Please refer to our only KB documentation link. 
 
KB documentation link exporting the large diagram in multipage. 
 
Regards, 
 
Naganathan K G 


Marked as answer
Loader.
Up arrow icon