using System.IO; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Xml; using System.Windows.Media.Imaging; using Microsoft.Win32; namespace DrawGraph { public class Export { public static void ToPng(Canvas canvas, string path) { RenderTargetBitmap renderBitmap = new RenderTargetBitmap( (int)canvas.Width, (int)canvas.Height, 96d, 96d, PixelFormats.Pbgra32); canvas.Measure(new Size((int)canvas.Width, (int)canvas.Height)); canvas.Arrange(new Rect(new Size((int)canvas.Width, (int)canvas.Height))); renderBitmap.Render(canvas); //JpegBitmapEncoder encoder = new JpegBitmapEncoder(); PngBitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(renderBitmap)); using (FileStream fs = new FileStream(path, FileMode.Create)) { encoder.Save(fs); } } public static void ToJpeg(Canvas canvas, string path) { RenderTargetBitmap renderBitmap = new RenderTargetBitmap( (int)canvas.Width, (int)canvas.Height, 96d, 96d, PixelFormats.Pbgra32); canvas.Measure(new Size((int)canvas.Width, (int)canvas.Height)); canvas.Arrange(new Rect(new Size((int)canvas.Width, (int)canvas.Height))); renderBitmap.Render(canvas); JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(renderBitmap)); using (FileStream fs = new FileStream(path, FileMode.Create)) { encoder.Save(fs); } } public static void Print(Canvas canvas) { PrintDialog pd = new PrintDialog(); if (pd.ShowDialog() == true) { pd.PrintVisual(canvas, "Printed with DrawGraph"); } } public static void ToGraphML(Node[] nodes) { // // < graphml xmlns = "http://graphml.graphdrawing.org/xmlns" //xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" //xsi: schemaLocation = "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd" > XmlDocument doc = new XmlDocument(); XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.AppendChild(declaration); XmlProcessingInstruction pi = doc.CreateProcessingInstruction("graphml", "xmlns=\"http://graphml.graphdrawing.org/xmlns \" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance \" xsi: schemaLocation = \"http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd \""); SaveFileDialog sfd = new SaveFileDialog(); var root = doc.CreateElement("graph"); foreach (var node in nodes) { var XNode = doc.CreateElement("node"); } sfd.Filter = "GraphML files (*.graphml)|*.graphml"; if (sfd.ShowDialog() == true) { doc.Save(sfd.FileName); } } } }