Example #1
0
        public void CopySvg()
        {
            var rc  = new CanvasRenderContext(null);
            var svg = SvgExporter.ExportToString(this.Model, this.Plot.ActualWidth, this.Plot.ActualHeight, true, rc);

            Clipboard.SetText(svg);
        }
Example #2
0
        private void CopySvg_Click(object sender, RoutedEventArgs e)
        {
            var rc  = new CanvasRenderContext(null);
            var svg = OxyPlot.SvgExporter.ExportToString(this.vm.Model, plot1.ActualWidth, plot1.ActualHeight, true, rc);

            Clipboard.SetText(svg);
        }
Example #3
0
        public RocWidgetManager(Manifold manifold, PlotView plot, bool showLabels)
        {
            this.manifold   = manifold;
            this.plot       = plot;
            this.showLabels = showLabels;

            var dm    = context.Resources.DisplayMetrics;
            var scale = dm.Density;

            rc = new CanvasRenderContext(scale, dm.ScaledDensity);
        }
        private void SaveSvg_Click(object sender, RoutedEventArgs e)
        {
            var d = new SaveFileDialog {
                Filter = "Svg files (*.svg)|*.svg", DefaultExt = ".svg"
            };

            if (true == d.ShowDialog())
            {
                using (var s = d.OpenFile())
                {
                    var rc = new CanvasRenderContext(new Canvas());
                    SvgExporter.Export(this.plot1.ActualModel, s, this.plot1.ActualWidth, this.plot1.ActualHeight, true, rc);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Exports the specified plot model to a stream.
        /// </summary>
        /// <param name="model">The plot model.</param>
        /// <param name="stream">The stream to write to.</param>
        /// <param name="width">The width of the export image.</param>
        /// <param name="height">The height of the exported image.</param>
        /// <param name="background">The background.</param>
        public static void Export(IPlotModel model, Stream stream, double width, double height, OxyColor background)
        {
            var canvas = new Canvas { Width = width, Height = height };
            if (background.IsVisible())
            {
                canvas.Background = background.ToBrush();
            }

            canvas.Measure(new Size(width, height));
            canvas.Arrange(new Rect(0, 0, width, height));

            var rc = new CanvasRenderContext(canvas);
            model.Update(true);
            model.Render(rc, width, height);

            canvas.UpdateLayout();
            var image = canvas.ToImage();
            image.WriteToStream(stream);
        }
Example #6
0
        /// <summary>
        /// Write the specified <see cref="IPlotModel" /> to the specified <see cref="XpsDocumentWriter" />.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="writer">The document writer.</param>
        private void Write(IPlotModel model, XpsDocumentWriter writer)
        {
            var canvas = new Canvas {
                Width = this.Width, Height = this.Height, Background = this.Background.ToBrush()
            };

            canvas.Measure(new Size(this.Width, this.Height));
            canvas.Arrange(new Rect(0, 0, this.Width, this.Height));

            var rc = new CanvasRenderContext(canvas);

            rc.TextFormattingMode = this.TextFormattingMode;

            model.Update(true);
            model.Render(rc, this.Width, this.Height);

            canvas.UpdateLayout();

            writer.Write(canvas);
        }
Example #7
0
        private void SavePlot_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new SaveFileDialog
            {
                Filter     = ".svg files|*.svg|.png files|*.png|.pdf files|*.pdf|.xaml files|*.xaml",
                DefaultExt = ".svg"
            };

            if (dlg.ShowDialog(this).Value)
            {
                var ext = Path.GetExtension(dlg.FileName).ToLower();
                switch (ext)
                {
                case ".png":
                    plot1.SaveBitmap(dlg.FileName, 0, 0, OxyColors.Automatic);
                    break;

                case ".svg":
                    var rc  = new CanvasRenderContext(null);
                    var svg = OxyPlot.SvgExporter.ExportToString(this.vm.Model, plot1.ActualWidth, plot1.ActualHeight, false, rc);
                    File.WriteAllText(dlg.FileName, svg);
                    break;

                case ".pdf":
                    using (var s = File.Create(dlg.FileName))
                    {
                        PdfExporter.Export(vm.Model, s, plot1.ActualWidth, plot1.ActualHeight);
                    }

                    break;

                case ".xaml":
                    plot1.SaveXaml(dlg.FileName);
                    break;
                }

                this.OpenContainingFolder(dlg.FileName);
            }
        }
Example #8
0
        /// <summary>
        /// Exports the specified plot model to a xml writer.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="writer">The xml writer.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="background">The background.</param>
        private static void Export(IPlotModel model, XmlWriter writer, double width, double height, OxyColor background)
        {
            var c = new Canvas();
            if (background.IsVisible())
            {
                c.Background = background.ToBrush();
            }

            c.Measure(new Size(width, height));
            c.Arrange(new Rect(0, 0, width, height));

            var rc = new CanvasRenderContext(c) { UseStreamGeometry = false };

            rc.TextFormattingMode = TextFormattingMode.Ideal;

            model.Update(true);
            model.Render(rc, width, height);

            c.UpdateLayout();

            XamlWriter.Save(c, writer);
        }
Example #9
0
        public void SaveSvg()
        {
            var path = this.GetFilename(".svg files|*.svg", ".svg");

            if (path != null)
            {
                // Using a WPF render context to measure the text
                var textMeasurer = new CanvasRenderContext(new Canvas());
                using (var s = File.Create(path))
                {
                    var exporter = new SvgExporter
                    {
                        Width        = this.Plot.ActualWidth,
                        Height       = this.Plot.ActualHeight,
                        IsDocument   = true,
                        TextMeasurer = textMeasurer
                    };
                    exporter.Export(this.Model, s);
                }

                OpenContainingFolder(path);
            }
        }
Example #10
0
        /// <summary>
        /// Exports the specified plot model to a bitmap.
        /// </summary>
        /// <param name="plotModel">The model to export.</param>
        /// <returns>A bitmap.</returns>
        public BitmapSource ExportToBitmap(IPlotModel plotModel)
        {
            var scale  = 96d / Resolution;
            var canvas = new Canvas {
                Width = Width * scale, Height = Height * scale, Background = Background.ToBrush()
            };

            canvas.Measure(new Size(canvas.Width, canvas.Height));
            canvas.Arrange(new Rect(0, 0, canvas.Width, canvas.Height));

            var context = new CanvasRenderContext(canvas)
            {
                RendersToScreen    = false,
                TextFormattingMode = TextFormattingMode.Ideal
            };

            plotModel.Update(true);
            plotModel.Render(context, canvas.Width, canvas.Height);
            //plotModel.Render(context, new OxyRect(0, 0, canvas.Width, canvas.Height));

            canvas.UpdateLayout();

            var renderTargetBitmap = new RenderTargetBitmap(Width, Height, Resolution, Resolution, PixelFormats.Pbgra32);

            renderTargetBitmap.Render(canvas);
            return(renderTargetBitmap);

            // alternative implementation:
            // http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx
            // var dv = new DrawingVisual();
            // using (var ctx = dv.RenderOpen())
            // {
            //    var vb = new VisualBrush(canvas);
            //    ctx.DrawRectangle(vb, null, new Rect(new Point(), new Size(width, height)));
            // }
            // bmp.Render(dv);
        }
Example #11
0
        /// <summary>
        /// Exports the specified plot model to a stream.
        /// </summary>
        /// <param name="model">The plot model.</param>
        /// <param name="stream">The stream to write to.</param>
        /// <param name="width">The width of the export image.</param>
        /// <param name="height">The height of the exported image.</param>
        /// <param name="background">The background.</param>
        public static void Export(IPlotModel model, Stream stream, double width, double height, OxyColor background)
        {
            var canvas = new Canvas {
                Width = width, Height = height
            };

            if (background.IsVisible())
            {
                canvas.Background = background.ToBrush();
            }

            canvas.Measure(new Size(width, height));
            canvas.Arrange(new Rect(0, 0, width, height));

            var rc = new CanvasRenderContext(canvas);

            model.Update(true);
            model.Render(rc, width, height);

            canvas.UpdateLayout();
            var image = canvas.ToImage();

            image.WriteToStream(stream);
        }
Example #12
0
        /// <summary>
        /// When overridden in a derived class, is invoked whenever application code or internal processes (such as a rebuilding layout pass) call <see cref="M:System.Windows.Controls.Control.ApplyTemplate" /> . In simplest terms, this means the method is called just before a UI element displays in an application. For more information, see Remarks.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            this.grid = this.GetTemplateChild(PartGrid) as Grid;
            if (this.grid == null)
            {
                return;
            }

            this.canvas = new Canvas();
            this.grid.Children.Add(this.canvas);
            this.canvas.UpdateLayout();
            this.renderContext = new CanvasRenderContext(this.canvas);

            this.overlays = new Canvas();
            this.grid.Children.Add(this.overlays);

            this.zoomControl = new ContentControl();
            this.overlays.Children.Add(this.zoomControl);
        }
Example #13
0
        /// <summary>
        /// Exports the specified plot model to a bitmap.
        /// </summary>
        /// <param name="model">The model to export.</param>
        /// <returns>A bitmap.</returns>
        public BitmapSource ExportToBitmap(IPlotModel model)
        {
            var scale = 96d / this.Resolution;
            var canvas = new Canvas { Width = this.Width * scale, Height = this.Height * scale, Background = this.Background.ToBrush() };
            canvas.Measure(new Size(canvas.Width, canvas.Height));
            canvas.Arrange(new Rect(0, 0, canvas.Width, canvas.Height));

            var rc = new CanvasRenderContext(canvas) { RendersToScreen = false };

            rc.TextFormattingMode = TextFormattingMode.Ideal;

            model.Update(true);
            model.Render(rc, canvas.Width, canvas.Height);

            canvas.UpdateLayout();

            var bmp = new RenderTargetBitmap(this.Width, this.Height, this.Resolution, this.Resolution, PixelFormats.Pbgra32);
            bmp.Render(canvas);
            return bmp;

            // alternative implementation:
            // http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx
            // var dv = new DrawingVisual();
            // using (var ctx = dv.RenderOpen())
            // {
            //    var vb = new VisualBrush(canvas);
            //    ctx.DrawRectangle(vb, null, new Rect(new Point(), new Size(width, height)));
            // }
            // bmp.Render(dv);
        }
Example #14
0
        public void SaveSvg()
        {
            var path = this.GetFilename(".svg files|*.svg", ".svg");
            if (path != null)
            {
                // Using a WPF render context to measure the text
                var textMeasurer = new CanvasRenderContext(new Canvas());
                using (var s = File.Create(path))
                {
                    var exporter = new SvgExporter
                    {
                        Width = this.Plot.ActualWidth,
                        Height = this.Plot.ActualHeight,
                        IsDocument = true,
                        TextMeasurer = textMeasurer
                    };
                    exporter.Export(this.Model, s);
                }

                OpenContainingFolder(path);
            }
        }
Example #15
0
 public void CopySvg()
 {
     var rc = new CanvasRenderContext(null);
     var svg = SvgExporter.ExportToString(this.Model, this.Plot.ActualWidth, this.Plot.ActualHeight, true, rc);
     Clipboard.SetText(svg);
 }
Example #16
0
 //private void SaveReport_Click(object sender, RoutedEventArgs e)
 //{
 //    var dlg = new SaveFileDialog { Filter = ".html files|*.html", DefaultExt = ".html" };
 //    if (dlg.ShowDialog(this).Value)
 //    {
 //        this.vm.SaveReport(dlg.FileName);
 //        this.OpenContainingFolder(dlg.FileName);
 //    }
 //}
 private void CopySvg_Click(object sender, RoutedEventArgs e)
 {
     var rc = new CanvasRenderContext(null);
     var svg = OxyPlot.SvgExporter.ExportToString(this.vm.Model, plot1.ActualWidth, plot1.ActualHeight, true, rc);
     Clipboard.SetText(svg);
 }
Example #17
0
        private void SavePlot_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new SaveFileDialog
            {
                Filter = ".svg files|*.svg|.png files|*.png|.pdf files|*.pdf|.xaml files|*.xaml",
                DefaultExt = ".svg"
            };
            if (dlg.ShowDialog(this).Value)
            {
                var ext = Path.GetExtension(dlg.FileName).ToLower();
                switch (ext)
                {
                    case ".png":
                        plot1.SaveBitmap(dlg.FileName, 0, 0, OxyColors.Automatic);
                        break;
                    case ".svg":
                        var rc = new CanvasRenderContext(new Canvas());
                        var svg = OxyPlot.SvgExporter.ExportToString(this.vm.Model, plot1.ActualWidth, plot1.ActualHeight, false, rc);
                        File.WriteAllText(dlg.FileName, svg);
                        break;
                    case ".pdf":
                        using (var s = File.Create(dlg.FileName))
                        {
                            PdfExporter.Export(vm.Model, s, plot1.ActualWidth, plot1.ActualHeight);
                        }

                        break;
                    case ".xaml":
                        plot1.SaveXaml(dlg.FileName);
                        break;
                }

                this.OpenContainingFolder(dlg.FileName);
            }
        }
Example #18
0
 public DicomPanelViewModel()
 {
     ImageBaseRenderContext = new WriteableBitmapRenderContext(ImageBase);
     ImageTopRenderContext  = new WriteableBitmapRenderContext(ImageBase);
     OverlayRenderContext   = new CanvasRenderContext(null);
 }
Example #19
0
 private void SaveSvg_Click(object sender, RoutedEventArgs e)
 {
     var d = new SaveFileDialog { Filter = "Svg files (*.svg)|*.svg", DefaultExt = ".svg" };
     if (true == d.ShowDialog())
     {
         using (var s = d.OpenFile())
         {
             var rc = new CanvasRenderContext(new Canvas());
             SvgExporter.Export(this.plot1.ActualModel, s, this.plot1.ActualWidth, this.plot1.ActualHeight, true, rc);
         }
     }
 }
Example #20
0
        /// <summary>
        /// Write the specified <see cref="IPlotModel" /> to the specified <see cref="XpsDocumentWriter" />.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="writer">The document writer.</param>
        private void Write(IPlotModel model, XpsDocumentWriter writer)
        {
            var canvas = new Canvas { Width = this.Width, Height = this.Height, Background = this.Background.ToBrush() };
            canvas.Measure(new Size(this.Width, this.Height));
            canvas.Arrange(new Rect(0, 0, this.Width, this.Height));

            var rc = new CanvasRenderContext(canvas);
            rc.TextFormattingMode = this.TextFormattingMode;

            model.Update(true);
            model.Render(rc, this.Width, this.Height);

            canvas.UpdateLayout();

            writer.Write(canvas);
        }