Esempio n. 1
0
        async Task Export()
        {
            message.Text = "Saving";
            var dialog = new SaveFileDialog();

            dialog.OverwritePrompt = true;
            dialog.Filter          = "PNG Files|*.png|SVG Files|*.svg";
            dialog.AddExtension    = true;
            if (dialog.ShowDialog(this) == true)
            {
                using (var fs = dialog.OpenFile())
                {
                    if (dialog.FileName.EndsWith(".svg", StringComparison.InvariantCultureIgnoreCase))
                    {
                        var exporter = new SvgExporter();
                        exporter.Export(plot.Model, fs);
                    }
                    else
                    {
                        var exporter = new PngExporter();
                        exporter.Export(plot.Model, fs);
                    }
                    fs.SetLength(fs.Position);
                }
            }
        }
Esempio n. 2
0
        void Copy_OnExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var data = new DataObject();

            using (var ms = new MemoryStream())
            {
                var pngExporter = new PngExporter();
                pngExporter.Export(plot.Model, ms);

                var bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.StreamSource = ms;
                bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                bitmap.EndInit();
                bitmap.Freeze();

                data.SetImage(bitmap);
            }

            var svg         = new MemoryStream();
            var svgExporter = new SvgExporter();

            svgExporter.Export(plot.Model, svg);
            svg.Position = 0;
            data.SetData("image/svg+xml", svg);

            Clipboard.SetDataObject(data);
            e.Handled = true;
        }
        /// <summary>
        /// The plot diagram.
        /// </summary>
        /// <param name="fileLocation">
        /// The png location.
        /// </param>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        private void PlotDiagram(string fileLocation, PlotModel model, int width, int height)
        {
            string extension = Path.GetExtension(fileLocation);
            if (extension == null)
            {
                throw new FileFormatException("Please specify file extension of the result picture file.");
            }
            else if (extension.ToLower() == ".svg")
            {
                using (var stream = File.Create(fileLocation))
                {
                    var exporter = new SvgExporter() { Width = width, Height = height};
                    exporter.Export(model, stream);
                }
            }
            else if (extension.ToLower() == ".png")
            {
                using (Stream stream = File.Create(fileLocation))
                {
                    PngExporter.Export(model, stream, width * 4, height * 4 , OxyColors.Transparent, 300);
                }

                // int resolution = 300;
                // RenderTargetBitmap image = new RenderTargetBitmap(width, height, resolution, resolution, PixelFormats.Pbgra32);
                // DrawingVisual drawVisual = new DrawingVisual();
                // DrawingContext drawContext = drawVisual.RenderOpen();
                //
                // // Output the graph models to a context
                // var oe = PngExporter.ExportToBitmap(model, width, height, OxyColors.White);
                // drawContext.DrawImage(oe, new Rect(0, 0, width, height));
                //
                // drawContext.Close();
                // image.Render(drawVisual);
                //
                // PngBitmapEncoder png = new PngBitmapEncoder();
                // png.Frames.Add(BitmapFrame.Create(image));
                // using (Stream stream = File.Create(fileLocation))
                // {
                //     png.Save(stream);
                // }
            }
            else
            {
                throw new FormatException(string.Format("Does not support plotting for picture format {0}.", extension));
            }
        }