Exemple #1
0
        /// <summary>
        /// Exports the specified plot model to a bitmap.
        /// </summary>
        /// <param name="model">The model to export.</param>
        /// <returns>A bitmap.</returns>
        public IBitmap ExportToBitmap(IPlotModel model)
        {
            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 rc = new CanvasRenderContext(canvas)
            {
                RendersToScreen = false
            };

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

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

            var bmp = new RenderTargetBitmap(new PixelSize(Width, Height));

            bmp.Render(canvas);
            return(bmp);
        }
Exemple #2
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>
        /// <param name="e">Event data for applying the template.</param>
        protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
        {
            base.OnApplyTemplate(e);
            panel = e.NameScope.Find(PartPanel) as Panel;
            if (panel == null)
            {
                return;
            }

            canvas = new Canvas();
            panel.Children.Add(canvas);
            renderContext = new CanvasRenderContext(canvas);

            overlays = new Canvas {
                Name = "Overlays"
            };
            panel.Children.Add(overlays);

            zoomControl = new ContentControl();
            overlays.Children.Add(zoomControl);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SvgExporter" /> class.
 /// </summary>
 public SvgExporter()
 {
     TextMeasurer = new CanvasRenderContext(new Canvas());
 }