/// <summary> /// Export the specified plot model to an xaml string. /// </summary> /// <param name="model">The model.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background.</param> /// <returns>A xaml string.</returns> public static string ExportToString(PlotModel model, double width, double height, OxyColor background = null) { var g = new Grid(); if (background != null) { g.Background = background.ToBrush(); } var c = new Canvas(); g.Children.Add(c); var size = new Size(width, height); g.Measure(size); g.Arrange(new Rect(0, 0, width, height)); g.UpdateLayout(); var rc = new ShapesRenderContext(c) { UseStreamGeometry = false }; model.Update(); model.Render(rc, width, height); var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) { var xw = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true }); XamlWriter.Save(c, xw); } return sb.ToString(); }
/// <summary> /// Prints the specified plot model. /// </summary> /// <param name="model">The model.</param> /// <param name="width">The width (using the actual media width if not specified).</param> /// <param name="height">The height (using the actual media height if not specified).</param> public static void Print(PlotModel model, double width = double.NaN, double height = double.NaN) { PrintDocumentImageableArea area = null; var xpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(ref area); if (xpsDocumentWriter != null) { if (double.IsNaN(width)) { width = area.MediaSizeWidth; } if (double.IsNaN(height)) { height = area.MediaSizeHeight; } var canvas = new Canvas { Width = width, Height = height }; canvas.Measure(new Size(width, height)); canvas.Arrange(new Rect(0, 0, width, height)); var rc = new ShapesRenderContext(canvas); model.Update(); model.Render(rc, width, height); canvas.UpdateLayout(); xpsDocumentWriter.Write(canvas); } }
/// <summary> /// Exports the specified plot model to a bitmap. /// </summary> /// <param name="model">The plot model.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background.</param> /// <param name="dpi">The resolution.</param> /// <returns>A bitmap.</returns> public static BitmapSource ExportToBitmap(PlotModel model, int width, int height, OxyColor background = null, int dpi = 96) { var canvas = new Canvas { Width = width, Height = height, Background = background.ToBrush() }; canvas.Measure(new Size(width, height)); canvas.Arrange(new Rect(0, 0, width, height)); var rc = new ShapesRenderContext(canvas) { RendersToScreen = false }; model.Update(); model.Render(rc, width, height); canvas.UpdateLayout(); var bmp = new RenderTargetBitmap(width, height, dpi, dpi, 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); }
public static void Save(PlotModel model, Stream s, double width, double height) { var svgrc = new PdfRenderContext(width, height); model.Render(svgrc); svgrc.Save(s); }
/// <summary> /// Exports the specified model to a stream. /// </summary> /// <param name="model"> /// The model. /// </param> /// <param name="s"> /// The stream. /// </param> /// <param name="width"> /// The width (points). /// </param> /// <param name="height"> /// The height (points). /// </param> public static void Export(PlotModel model, Stream s, double width, double height) { using (var rc = new PdfRenderContext(width, height, model.Background)) { model.Update(); model.Render(rc, width, height); rc.Save(s); } }
/// <summary> /// Draw the specified rect. /// </summary> /// <param name='rect'> /// Rect. /// </param> public override void Draw(System.Drawing.RectangleF rect) { plot.PlotMargins = new OxyThickness(10); plot.Background = OxyColors.Transparent; plot.Update(true); RectangleF big_rect = rect; big_rect.Width = rect.Width * UIScreen.MainScreen.Scale; big_rect.Height = rect.Height * UIScreen.MainScreen.Scale; big_rect.X = rect.X; big_rect.Y = rect.Y; SizeF new_image_size = new SizeF(big_rect.Width, big_rect.Height); UIGraphics.BeginImageContextWithOptions(new_image_size, false, 1); CGContext context = UIGraphics.GetCurrentContext(); context.SaveState(); context.InterpolationQuality = CGInterpolationQuality.High; MonoTouchRenderContext renderer = new MonoTouchRenderContext(context, big_rect); AdjustPlotChartMargins(plot, rect.Width * UIScreen.MainScreen.Scale, rect.Height * UIScreen.MainScreen.Scale); context.TranslateCTM(0.0f, big_rect.Height); context.ScaleCTM(1.0f, -1.0f); plot.Render(renderer); UIImage resulting_plot_image = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); CGContext original_context = UIGraphics.GetCurrentContext(); original_context.InterpolationQuality = CGInterpolationQuality.High; original_context.DrawImage(rect, resulting_plot_image.CGImage); context.RestoreState(); }
/// <summary> /// The export. /// </summary> /// <param name="model"> /// The model. /// </param> /// <param name="fileName"> /// The file name. /// </param> /// <param name="width"> /// The width. /// </param> /// <param name="height"> /// The height. /// </param> /// <param name="background"> /// The background. /// </param> public static void Export(PlotModel model, string fileName, int width, int height, Brush background = null) { using (var bm = new Bitmap(width, height)) { using (Graphics g = Graphics.FromImage(bm)) { if (background != null) { g.FillRectangle(background, 0, 0, width, height); } var rc = new GraphicsRenderContext { RendersToScreen = false }; rc.SetGraphicsTarget(g); model.Update(); model.Render(rc, width, height); bm.Save(fileName, ImageFormat.Png); } } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); var rc = new GraphicsRenderContext(this, e.Graphics, e.ClipRectangle); if (model != null) { model.Render(rc); } if (zoomRectangle != Rectangle.Empty) { using (var zoomBrush = new SolidBrush(Color.FromArgb(0x40, 0xFF, 0xFF, 0x00))) using (var zoomPen = new Pen(Color.Black)) { zoomPen.DashPattern = new float[] { 3, 1 }; e.Graphics.FillRectangle(zoomBrush, zoomRectangle); e.Graphics.DrawRectangle(zoomPen, zoomRectangle); } } }
public static void Export(PlotModel model, string fileName, int width, int height, Brush background)// = null) { using (var bm = new Bitmap(width, height)) { using (Graphics g = Graphics.FromImage(bm)) { if (background != null) { g.FillRectangle(background, 0, 0, width, height); } var rc = new GraphicsRenderContext { RendersToScreen = false }; rc.SetGraphicsTarget(g); model.Update(); model.Render(rc, width, height); bm.Save(fileName, ImageFormat.Png); } } }
/// <summary> /// Export the specified plot model to an xaml string. /// </summary> /// <param name="model">The model.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background.</param> /// <returns>A xaml string.</returns> public static string ExportToString(PlotModel model, double width, double height, OxyColor background = null) { var g = new Grid(); if (background != null) { g.Background = background.ToBrush(); } var c = new Canvas(); g.Children.Add(c); var size = new Size(width, height); g.Measure(size); g.Arrange(new Rect(0, 0, width, height)); g.UpdateLayout(); var rc = new ShapesRenderContext(c) { UseStreamGeometry = false }; model.Update(); model.Render(rc, width, height); var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) { var xw = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true }); XamlWriter.Save(c, xw); } return(sb.ToString()); }
/// <summary> /// Exports the specified plot model to an xps file. /// </summary> /// <param name="model">The model.</param> /// <param name="fileName">The file name.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background color.</param> public static void Export( PlotModel model, string fileName, double width, double height, OxyColor background = null) { using (var xpsPackage = Package.Open(fileName, FileMode.Create, FileAccess.ReadWrite)) { using (var doc = new XpsDocument(xpsPackage)) { var canvas = new Canvas { Width = width, Height = height, Background = background.ToBrush() }; canvas.Measure(new Size(width, height)); canvas.Arrange(new Rect(0, 0, width, height)); var rc = new ShapesRenderContext(canvas); model.Update(); model.Render(rc, width, height); canvas.UpdateLayout(); var xpsdw = XpsDocument.CreateXpsDocumentWriter(doc); xpsdw.Write(canvas); } } }
private void UpdateVisuals() { if (canvas != null) { canvas.Children.Clear(); } if (internalModel == null) { return; } if (Title != null) { internalModel.Title = Title; } if (Subtitle != null) { internalModel.Subtitle = Subtitle; } if (canvas != null) { var wrc = new ShapesRenderContext(canvas); internalModel.Render(wrc); } if (plotFrame != null) { plotFrame.Model = internalModel; plotAliasedFrame.Model = internalModel; plotFrame.InvalidateVisual(); plotAliasedFrame.InvalidateVisual(); } }
/// <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(PlotModel model, Stream stream, double width, double height, OxyColor background = null) { var canvas = new Canvas { Width = width, Height = height }; if (background != null) { canvas.Background = background.ToBrush(); } canvas.Measure(new Size(width, height)); canvas.Arrange(new Rect(0, 0, width, height)); var rc = new SilverlightRenderContext(canvas); model.Update(); model.Render(rc, width, height); canvas.UpdateLayout(); var image = canvas.ToImage(); image.WriteToStream(stream); }
/// <summary> /// Exports the specified plot model to a bitmap. /// </summary> /// <param name="model">The plot model.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background.</param> /// <param name="dpi">The resolution.</param> /// <returns>A bitmap.</returns> public static BitmapSource ExportToBitmap(PlotModel model, int width, int height, OxyColor background = null, int dpi = 96) { var canvas = new Canvas { Width = width, Height = height, Background = background.ToBrush() }; canvas.Measure(new Size(width, height)); canvas.Arrange(new Rect(0, 0, width, height)); var rc = new ShapesRenderContext(canvas) { RendersToScreen = false }; model.Update(); model.Render(rc, width, height); canvas.UpdateLayout(); var bmp = new RenderTargetBitmap(width, height, dpi, dpi, 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); }