Exporting the diagram as an Image is a feature that we intend to provide in a future version of Essential Diagram. For the time being you can use the appended code snippet to publish the Diagram contents as an image object.
// The activeDiagram member in this snippet
// references the Diagram control
// Cache the view''s current origin and size
PointF vieworigin = activeDiagram.View.Origin;
Size viewsize = activeDiagram.View.Size;
// Set the view''s origin and size to
// encompass the whole diagram
activeDiagram.View.Origin = new PointF(0, 0);
activeDiagram.View.Size = new Size((int)activeDiagram.Model.Width, (int)activeDiagram.Model.Height);
// Create a Bitmap equal to the model
// dimensions and create a Graphics object
// from the image
Bitmap diagramimage = new Bitmap((int)activeDiagram.Model.Width, (int)activeDiagram.Model.Height);
Graphics bmpgrfx = Graphics.FromImage(diagramimage);
// Draw the Diagram.View''s contents onto
// the Image Graphics object
// The diagramimage is now a full rendering
// of the Diagram contents and can be used
// in any format
// Restore the View''s origin and size
activeDiagram.View.Origin = vieworigin;
activeDiagram.View.Size = viewsize;
RIRichJune 21, 2004 12:58 AM UTC
This saves the file, but the diagram component does not refresh after the save until the drawing surface is clicked. I have tried the following lines with no avail
RIRichJune 21, 2004 01:02 AM UTC
I am using this as part of an MDI, in case this makes any difference
AdministratorJune 22, 2004 11:07 AM UTC
The Diagram''s Model.UpdateViews() method will force an update of all views tied to the diagram model.
AdministratorOctober 11, 2004 06:59 PM UTC
Hi, Prakash --
I''m afraid that the Export to Bitmap functionality doesn''t work well. As with all other image rendering in Diagram, the problem is when you change GraphicsUnits. I set the Diagram''s GraphicsUnits to Millimeters. However, that doesn''t work when the Bitmap size is set. If my Diagram is 280 or so mm wide, the image that''s created is only 280 pixels wide.
The export also exports the View''s Rulers.
The 2 attached images show the original screenshot of the full Diagram that I attempted to export, and the other image shows the exported image.
The code needs to convert from the ints for whatever GraphicsUnits are set in the active Diagram to dimensions that are appropriate for a Bitmap. It also needs to save whether the Ruler is showing, then hide it if it''s showing, and turn off the Grid (and restore it later).
Of course, I can do the latter 2 steps easily enough, but are there any built in conversion utilities that can convert the ints for the Diagram''s dimensions in MM to dimensions appropriate for a Bitmap? It would be nice if there were a method like:
Size bitmapSize = GetSizeForBitmap(activeDiagram)
This method could inspect the Diagram and dynamically make the right conversions depending on what the Diagram''s GraphicsUnits are set to.
Yes, we can see this problem. Thanks also for your feedback on this issue with reference to the Rulers being visible. I am going ahead and logging a high priority QA incident on this issue.
Do not hesitate to contact us if you have any further questions.