Articles in this section
Category / Section

How can I save my Diagram as a bitmap?

2 mins read

How can I save my Diagram as a bitmap?

The following code sample shows how you can export your diagram as an image such as a bitmap:

[C#]

// Cache the view's current origin and size PointF vieworigin = this.diagram1.View.Origin; Size viewsize = this.diagram1.View.Size;
// Set the view''s origin and size to // encompass the whole diagram this.diagram1.View.Origin = new PointF(0, 0); this.diagram1.View.Size = new Size((int)this.diagram1.Model.Width, (int)this.diagram1.Model.Height);
// Create a Bitmap equal to the model // dimensions and create a Graphics object // from the image Bitmap diagramimage = new Bitmap((int)this.diagram1.Model.Width, (int)this.diagram1.Model.Height); Graphics bmpgrfx = Graphics.FromImage(diagramimage);
// Draw the Diagram.View''s contents onto // the Image Graphics object this.diagram1.View.Draw(bmpgrfx); bmpgrfx.Dispose();
// The diagramimage is now a full rendering // of the Diagram contents and can be used // in any format diagramimage.Save("C:\\mydiagram.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
// Restore the View''s origin and size this.diagram1.View.Origin = vieworigin; this.diagram1.View.Size = viewsize; 

 

 [VB.NET]

' Cache the view's current origin and size Dim vieworigin As PointF =  Me.diagram1.View.Origin Dim viewsize As Size =  Me.diagram1.View.Size   ' Set the view''s origin and size to ' encompass the whole diagram Me.diagram1.View.Origin = New PointF(0, 0) Me.diagram1.View.Size = New Size(CType(Me.diagram1.Model.Width, CType(Me.diagram1.Model.Height, int, Integer)))   ' Create a Bitmap equal to the model ' dimensions and create a Graphics object ' from the image Dim diagramimage As Bitmap =  New Bitmap(CType(Me.diagram1.Model.Width,CType(Me.diagram1.Model.Height, int, Integer))) Dim bmpgrfx As Graphics =  Graphics.FromImage(diagramimage)   ' Draw the Diagram.View''s contents onto ' the Image Graphics object Me.diagram1.View.Draw(bmpgrfx) bmpgrfx.Dispose()   ' The diagramimage is now a full rendering ' of the Diagram contents and can be used ' in any format diagramimage.Save("C:\\mydiagram.bmp", System.Drawing.Imaging.ImageFormat.Bmp)   ' Restore the View''s origin and size Me.diagram1.View.Origin = vieworigin Me.diagram1.View.Size = viewsize

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied