We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How can I save my Diagram as a bitmap?

Platform: WinForms |
Control: Diagram |
Published Date: April 30, 2011 |
Last Revised Date: July 10, 2014

 

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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon