Articles in this section
Category / Section

How can I save my Diagram as a bitmap?

3 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

 

Conclusion

I hope you enjoyed learning about how you can save your Diagram as a bitmap.

You can refer to WinForms Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Diagram example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

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