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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Article ID: Published Date: Last Revised Date: Platform: Control:
173 04/30/2011 07/10/2014 Windows Forms Diagram
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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