/// <summary> /// Exports the specified <see cref="PlotModel" /> to the specified <see cref="Stream" />. /// </summary> /// <param name="model">The model.</param> /// <param name="stream">The output stream.</param> public void Export(IPlotModel model, Stream stream) { using (var bm = new Bitmap(this.Width, this.Height)) { using (var g = Graphics.FromImage(bm)) { if (this.Background.IsVisible()) { using (var brush = this.Background.ToBrush()) { g.FillRectangle(brush, 0, 0, this.Width, this.Height); } } using (var rc = new GraphicsRenderContext(g) { RendersToScreen = false }) { model.Update(true); model.Render(rc, this.Width, this.Height); } bm.Save(stream, ImageFormat.Png); } } }
/// <summary> /// Exports the specified <see cref="PlotModel" /> to a <see cref="Bitmap" />. /// </summary> /// <param name="model">The model to export.</param> /// <returns>A bitmap.</returns> public Bitmap ExportToBitmap(IPlotModel model) { var bm = new Bitmap(this.Width, this.Height); using (var g = Graphics.FromImage(bm)) { if (model.Background.IsVisible()) { using (var brush = model.Background.ToBrush()) { g.FillRectangle(brush, 0, 0, this.Width, this.Height); } } using (var rc = new GraphicsRenderContext(g) { RendersToScreen = false }) { model.Update(true); model.Render(rc, new OxyRect(0, 0, this.Width, this.Height)); } bm.SetResolution((float)this.Resolution, (float)this.Resolution); return(bm); } }
/// <summary> /// Creates an SVG string. /// </summary> /// <param name="model">The model.</param> /// <param name="width">The width (points).</param> /// <param name="height">The height (points).</param> /// <param name="isDocument">if set to <c>true</c>, the xml headers will be included (?xml and !DOCTYPE).</param> /// <returns>A <see cref="string" />.</returns> public static string ToSvg(this PlotModel model, double width, double height, bool isDocument) { using (var g = Graphics.FromHwnd(IntPtr.Zero)) { using (var rc = new GraphicsRenderContext(g) { RendersToScreen = false }) { return OxyPlot.SvgExporter.ExportToString(model, width, height, isDocument, rc); } } }
/// <summary> /// Initializes a new instance of the <see cref="PlotView" /> class. /// </summary> public PlotView() { this.renderContext = new GraphicsRenderContext(); // ReSharper disable DoNotCallOverridableMethodsInConstructor this.DoubleBuffered = true; // ReSharper restore DoNotCallOverridableMethodsInConstructor this.PanCursor = Cursors.Hand; this.ZoomRectangleCursor = Cursors.SizeNWSE; this.ZoomHorizontalCursor = Cursors.SizeWE; this.ZoomVerticalCursor = Cursors.SizeNS; }
/// <summary> /// Creates an SVG string. /// </summary> /// <param name="model">The model.</param> /// <param name="width">The width (points).</param> /// <param name="height">The height (points).</param> /// <param name="isDocument">if set to <c>true</c>, the xml headers will be included (?xml and !DOCTYPE).</param> /// <returns>A <see cref="string" />.</returns> public static string ToSvg(this PlotModel model, double width, double height, bool isDocument) { using (var g = Graphics.FromHwnd(IntPtr.Zero)) { using (var rc = new GraphicsRenderContext(g) { RendersToScreen = false }) { return(OxyPlot.SvgExporter.ExportToString(model, width, height, isDocument, rc)); } } }
/// <summary> /// Initializes a new instance of the <see cref="PlotView" /> class. /// </summary> public PlotView() { this.renderContext = new GraphicsRenderContext(); // ReSharper disable DoNotCallOverridableMethodsInConstructor this.DoubleBuffered = true; // ReSharper restore DoNotCallOverridableMethodsInConstructor this.PanCursor = Cursors.Hand; this.ZoomRectangleCursor = Cursors.SizeNWSE; this.ZoomHorizontalCursor = Cursors.SizeWE; this.ZoomVerticalCursor = Cursors.SizeNS; var DoCopy = new DelegatePlotCommand <OxyKeyEventArgs>((view, controller, args) => this.DoCopy(view, args)); this.ActualController.BindKeyDown(OxyKey.C, OxyModifierKeys.Control, DoCopy); }
/// <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 Image DoCreateChartImage() { var plotModel = new PlotModel(""); var ls = new LineSeries("") { Points = Parameters.SeriaData.Select(t => new DataPoint(t.Key, t.Value) as IDataPoint).ToList() }; plotModel.Series.Add(ls); plotModel.Axes.Add(new LinearAxis(AxisPosition.Left)); plotModel.Axes.Add(new LinearAxis(AxisPosition.Bottom)); var bitmap = new Bitmap(Parameters.ChartWidth, Parameters.ChartHeight); using (var graphics = Graphics.FromImage(bitmap)) { var graphicsRenderContext = new GraphicsRenderContext { RendersToScreen = false }; graphicsRenderContext.SetGraphicsTarget(graphics); plotModel.Update(); plotModel.Render(graphicsRenderContext, Parameters.ChartWidth, Parameters.ChartHeight); return bitmap; } }
/// <summary> /// Initializes a new instance of the <see cref="SvgExporter" /> class. /// </summary> public SvgExporter() { this.g = Graphics.FromHwnd(IntPtr.Zero); this.TextMeasurer = this.grc = new GraphicsRenderContext(this.g); }
static void CreateSvg(int size, IconRenderer iconRenderer, string fileName) { using (var bm = new Bitmap(size, size)) { using (var grx = new GraphicsRenderContext(Graphics.FromImage(bm))) { using (var s = File.Create(fileName)) { using (var rc = new SvgRenderContext(s, size, size, true, grx, OxyColors.Transparent)) { iconRenderer.Render(rc, size); } } } } }
static void CreateBitmap(int size, IconRenderer iconRenderer, string fileName, double cornerRadius = 0) { using (var bm = new Bitmap(size, size, PixelFormat.Format32bppArgb)) { using (var g = Graphics.FromImage(bm)) { g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.CompositingQuality = CompositingQuality.HighQuality; g.CompositingMode = CompositingMode.SourceOver; using (var rc = new GraphicsRenderContext(g) { RendersToScreen = false }) { g.Clear(Color.Transparent); if (cornerRadius > 0) { // TODO: no antialiasing on the clipping path? var path = GetRoundedRect(new RectangleF(0, 0, size, size), (float)cornerRadius); g.SetClip(path, CombineMode.Replace); } iconRenderer.Render(rc, size); } bm.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); } } }
/// <summary> /// Exports the specified <see cref="PlotModel" /> to a <see cref="Bitmap" />. /// </summary> /// <param name="model">The model to export.</param> /// <returns>A bitmap.</returns> public Bitmap ExportToBitmap(IPlotModel model) { var bm = new Bitmap(this.Width, this.Height); using (var g = Graphics.FromImage(bm)) { if (this.Background.IsVisible()) { using (var brush = this.Background.ToBrush()) { g.FillRectangle(brush, 0, 0, this.Width, this.Height); } } using (var rc = new GraphicsRenderContext(g) { RendersToScreen = false }) { model.Update(true); model.Render(rc, this.Width, this.Height); } bm.SetResolution(this.Resolution, this.Resolution); return bm; } }