/// <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="resolution">The resolution (dpi).</param> /// <returns>A bitmap.</returns> public static BitmapSource ExportToBitmap( PlotModel model, int width, int height, OxyColor background, int resolution = 96) { var exporter = new PngExporter { Width = width, Height = height, Background = background, Resolution = resolution }; return(exporter.ExportToBitmap(model)); }
/// <summary> /// Saves the PlotView as a bitmap. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> public void SaveBitmap(string fileName, int width, int height) { if (width <= 0) { width = (int)this.ActualWidth; } if (height <= 0) { height = (int)this.ActualHeight; } PngExporter.Export(this.ActualModel, fileName, width, height); }
/// <summary> /// Performs the copy operation. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs" /> instance containing the event data.</param> private void DoCopy(object sender, ExecutedRoutedEventArgs e) { var background = this.ActualModel.Background.IsVisible() ? this.ActualModel.Background : this.Background.ToOxyColor(); if (background.IsInvisible()) { background = OxyColors.White; } var bitmap = PngExporter.ExportToBitmap( this.ActualModel, (int)this.ActualWidth, (int)this.ActualHeight, background); Clipboard.SetImage(bitmap); }
/// <summary> /// Saves the PlotView as a bitmap. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background.</param> public void SaveBitmap(string fileName, int width, int height, OxyColor background) { if (width == 0) { width = (int)this.ActualWidth; } if (height == 0) { height = (int)this.ActualHeight; } if (background.IsAutomatic()) { background = this.Background.ToOxyColor(); } PngExporter.Export(this.ActualModel, fileName, width, height, background); }
/// <summary> /// Method to invoke when the ExportPngCommand command is executed. /// </summary> private async Task OnExportPngCommandExecute() { var saveFileService = ServiceLocator.Default.ResolveType <ISaveFileService>(); try { saveFileService.Filter = "Plot Image|*.png"; if (!string.IsNullOrEmpty(PlotModel.SavePngPath)) { saveFileService.InitialDirectory = Path.GetDirectoryName(PlotModel.SavePngPath); if (!Directory.Exists(saveFileService.InitialDirectory)) { saveFileService.InitialDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\Data")); } saveFileService.FileName = Path.GetFileNameWithoutExtension(PlotModel.SavePngPath); } else { saveFileService.InitialDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\Data")); } if (saveFileService.DetermineFile()) { var pngExporter = new OxyPlot.Wpf.PngExporter { Width = (int)OxyPlotModel.Width, Height = (int)OxyPlotModel.Height, Background = OxyColors.White }; pngExporter.ExportToFile(OxyPlotModel, saveFileService.FileName); if (PlotModel.SavePngPath != saveFileService.FileName) { PlotModel.SavePngPath = saveFileService.FileName; } LogTo.Info("Saved Plot image to: {0}", PlotModel.SavePngPath); } } catch (Exception ex) { string errmsg = string.Format("Error saving Plot image: {0}", ex.Message); LogTo.Error(errmsg); await Shared.Utility.ShowErrorMsgAsync(this, errmsg); } }
/// <summary> /// Renders the PlotView to a bitmap. /// </summary> /// <returns>A bitmap.</returns> public BitmapSource ToBitmap() { return(PngExporter.ExportToBitmap(this.ActualModel, (int)this.ActualWidth, (int)this.ActualHeight, this.Background.ToOxyColor())); }
/// <summary> /// Renders the PlotView to a bitmap. /// </summary> /// <returns>A bitmap.</returns> public BitmapSource ToBitmap() { var background = this.ActualModel.Background.IsVisible() ? this.ActualModel.Background : this.Background.ToOxyColor(); return(PngExporter.ExportToBitmap(this.ActualModel, (int)this.ActualWidth, (int)this.ActualHeight, background)); }
/// <summary> /// Exports the specified plot model to a stream. /// </summary> /// <param name="model">The model to export.</param> /// <param name="stream">The stream.</param> /// <param name="width">The width of the output bitmap.</param> /// <param name="height">The height of the output bitmap.</param> /// <param name="background">The background color. The default value is <c>null</c>.</param> /// <param name="resolution">The resolution (resolution). The default value is 96.</param> public static void Export(PlotModel model, Stream stream, int width, int height, OxyColor background, int resolution = 96) { var exporter = new PngExporter { Width = width, Height = height, Background = background, Resolution = resolution }; exporter.Export(model, stream); }
public void export(string outputFolder) { string fileName; //as png fileName = outputFolder + "/" + name + ".png"; var pngExporter = new PngExporter { Width = 600, Height = 400, Background = OxyColors.Transparent }; pngExporter.ExportToFile(m_plot, fileName); //as svg fileName = outputFolder + "/" + name + ".svg"; var svgExporter = new OxyPlot.Wpf.SvgExporter { Width = 600, Height = 400 }; svgExporter.ExportToFile(m_plot, fileName); }
/// <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="resolution">The resolution (dpi).</param> /// <returns>A bitmap.</returns> public static BitmapSource ExportToBitmap( PlotModel model, int width, int height, OxyColor background, int resolution = 96) { var exporter = new PngExporter { Width = width, Height = height, Background = background, Resolution = resolution }; return exporter.ExportToBitmap(model); }