public void ExportToFile() { var plotModel = TestModels.CreateTestModel1(); const string FileName = "PngExporterTests_Plot1.png"; var exporter = new PngExporter { Width = 400, Height = 300 }; exporter.ExportToFile(plotModel, FileName); Assert.IsTrue(File.Exists(FileName)); }
public void ExportToStream() { var plotModel = TestModels.CreateTestModel1(); var exporter = new PngExporter { Width = 400, Height = 300 }; var stream = new MemoryStream(); exporter.Export(plotModel, stream); Assert.IsTrue(stream.Length > 0); }
private BitmapSource ExportToBitMap(IPlotModel plot, int width, int height, OxyColor background, int resolution) { var exporter = new PngExporter { Width = width, Height = height, Background = background, Resolution = resolution }; return(exporter.ExportToBitmap(plot)); }
private static void Export(PlotModel model, string name) { var fileName = Path.Combine(OutputDirectory, name + ".png"); var directory = Path.GetDirectoryName(fileName) ?? "."; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } if (ExportPng) { Console.WriteLine(fileName); using (var stream = File.Create(fileName)) { var exporter = new PngExporter { Width = 600, Height = 400 }; exporter.Export(model, stream); } OptimizePng(fileName); } if (ExportPdf) { fileName = Path.ChangeExtension(fileName, ".pdf"); Console.WriteLine(fileName); using (var stream = File.Create(fileName)) { var exporter = new PdfExporter { Width = 600d * 72 / 96, Height = 400d * 72 / 96 }; exporter.Export(model, stream); } } if (ExportSvg) { fileName = Path.ChangeExtension(fileName, ".svg"); Console.WriteLine(fileName); using (var stream = File.Create(fileName)) { using (var exporter = new OxyPlot.WindowsForms.SvgExporter { Width = 600, Height = 400, IsDocument = true }) { exporter.Export(model, stream); } } } }
public void ExportWithDifferentBackground() { var plotModel = TestModels.CreateTestModel1(); const string FileName = "PngExporterTests_BackgroundYellow.png"; var exporter = new PngExporter { Width = 400, Height = 300, Background = OxyColors.Yellow }; using (var stream = File.OpenWrite(FileName)) { exporter.Export(plotModel, stream); } Assert.IsTrue(File.Exists(FileName)); }
private void menuSaveAsPng_Click(object sender, RoutedEventArgs e) { string fileName = SaveFile("", "Kaydet", "İmaj dosyası (*.png)|*.png"); if (!string.IsNullOrEmpty(fileName)) { var pngExporter = new PngExporter { Width = 600, Height = 400, Background = OxyColors.White }; pngExporter.ExportToFile(PlotView.Model, fileName); } }
public void ExportToClipboard() { System.IO.MemoryStream stream = new System.IO.MemoryStream(); PngExporter pngExporter = new PngExporter(); pngExporter.Width = 800; pngExporter.Height = 600; pngExporter.Export(plots[0].Model, stream); Clipboard cb = MainWidget.GetClipboard(Gdk.Selection.Clipboard); cb.Image = new Gdk.Pixbuf(stream); }
public void ExportToStream() { var plotModel = CreateTestModel1(); var exporter = new PngExporter { Width = 400, Height = 300 }; var stream = new MemoryStream(); exporter.Export(plotModel, stream); Assert.IsTrue(stream.Length > 0); }
public void ExportToFile() { var plotModel = TestModels.CreateTestModel1(); const string FileName = "PngExporterTests_Plot1.png"; var exporter = new PngExporter { Width = 400, Height = 300 }; using (var stream = File.OpenWrite(FileName)) { exporter.Export(plotModel, stream); } Assert.IsTrue(File.Exists(FileName)); }
public void ExportToFile() { var plotModel = CreateTestModel1(); const string FileName = "PngExporterTests_Plot1.png"; var exporter = new PngExporter { Width = 400, Height = 300 }; exporter.ExportToFile(plotModel, FileName); Assert.IsTrue(File.Exists(FileName)); }
/// <summary> /// Saves an image of the given size for the model provided at the path suggested. /// </summary> /// <param name="model"></param> /// <param name="path"></param> /// <param name="size"></param> public void SaveImage(PlotModel model, string path, Size size) { using (var stream = File.Create(path)) { var pngExporter = new PngExporter { Width = (int)size.Width, Height = (int)size.Height }; pngExporter.Export(model, stream); } }
/// <summary> /// Export a plot model to an image. /// </summary> /// <param name="plot">Plot model to be exported.</param> /// <param name="width">Desired width of the image (in px).</param> /// <param name="height">Desired height of the image (in px).</param> public Image Export(IPlotModel plot, double width, double height) { using (Stream stream = new MemoryStream()) { PngExporter exporter = new PngExporter(); exporter.Height = (int)height; exporter.Width = (int)width; exporter.UseTextShaping = false; exporter.Export(plot, stream); stream.Seek(0, SeekOrigin.Begin); return(Image.FromStream(stream)); } }
/// <summary> /// Export the graph to the clipboard /// </summary> public void ExportToClipboard() { MemoryStream stream = new MemoryStream(); PngExporter pngExporter = new PngExporter(); pngExporter.Width = 800; pngExporter.Height = 600; pngExporter.Export(plot1.Model, stream); stream.Seek(0, SeekOrigin.Begin); Clipboard cb = MainWidget.GetClipboard(Gdk.Selection.Clipboard); cb.Image = new Gdk.Pixbuf(stream); }
private void SaveButton_Click(object sender, RoutedEventArgs e) { PngExporter x = new PngExporter(); var dialog = new SaveFileDialog() { Filter = "Image Files (*.png)|*.png;" }; if (dialog.ShowDialog() == true) { x.ExportToFile(StatModel, dialog.FileName); } }
public void Export() { if (Path.EndsWith(".png")) { var pngExporter = new PngExporter { Width = Settings.Sizes.Width, Height = Settings.Sizes.Height, Background = OxyColor.FromArgb(Settings.GraphColor.A, Settings.GraphColor.R, Settings.GraphColor.G, Settings.GraphColor.B) }; pngExporter.ExportToFile(MyModel, Path); } }
private static void MakeBarPlot([JetBrains.Annotations.NotNull] string outputPath, [ItemNotNull][JetBrains.Annotations.NotNull] List <Column> columns, int position, int day, int minutesToSum) { var plotModel2 = new PlotModel(); var p = OxyPalettes.HueDistinct(columns.Count); plotModel2.LegendPosition = LegendPosition.BottomCenter; plotModel2.LegendPlacement = LegendPlacement.Outside; plotModel2.LegendOrientation = LegendOrientation.Horizontal; plotModel2.Title = "Day " + day; // axes var categoryAxis = new CategoryAxis { AbsoluteMinimum = 0, MinimumPadding = 0, GapWidth = 0, MajorStep = 60, Title = "Energy" }; plotModel2.Axes.Add(categoryAxis); var linearAxis2 = new LinearAxis { AbsoluteMinimum = 0, MaximumPadding = 0.06, MinimumPadding = 0, Title = "Minutes" }; plotModel2.Axes.Add(linearAxis2); for (var i = 1; i < columns.Count; i++) { var columnSeries2 = new ColumnSeries { IsStacked = true, StrokeThickness = 0, Title = columns[i].HHNumber }; for (var j = position; j < position + 1440; j += minutesToSum) { columnSeries2.Items.Add(new ColumnItem(columns[i].MakeSum(j, minutesToSum))); } columnSeries2.FillColor = p.Colors[i]; plotModel2.Series.Add(columnSeries2); } var path2 = Path.Combine(outputPath, "Plot." + day + "." + minutesToSum + "min.bar.png"); PngExporter.Export(plotModel2, path2, 3200, 1600, OxyColor.FromRgb(255, 255, 255), 100); }
private void saveData_Click(object sender, EventArgs e) { ClosePort(); UpdateStatus(); try { var dialog = new SaveFileDialog(); dialog.InitialDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); dialog.Filter = "bin (*.bin)|*.bin|png (*.png)|*.png"; dialog.FilterIndex = 1; dialog.RestoreDirectory = true; dialog.CheckFileExists = false; var result = dialog.ShowDialog(); if (result == DialogResult.OK) { if (dialog.FileName.Contains(".png")) { var pngExporter = new PngExporter { Width = oxyView.Width, Height = oxyView.Height, Background = OxyColors.White }; pngExporter.ExportToFile(_oxyPlot, dialog.FileName); } else if (dialog.FileName.Contains(".bin")) { using (var writer = new BinaryWriter(new FileStream(dialog.FileName, FileMode.OpenOrCreate, FileAccess.Write))) { writer.Write((UInt32)_dataPsi.Points.Count); writer.Write((UInt32)_dataCas2.Points.Count); foreach (var pt in _dataPsi.Points) { writer.Write((float)pt.X); writer.Write((float)pt.Y); } foreach (var pt in _dataCas2.Points) { writer.Write((float)pt.X); writer.Write((float)pt.Y); } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void ExportToPngExecute(object parameter) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "png File|*.png"; saveFileDialog.Title = "Save an png File"; saveFileDialog.ShowDialog(); // If the file name is not an empty string open it for saving. if (saveFileDialog.FileName != "") { PngExporter.Export(PlotModel, saveFileDialog.FileName, 1000, 700, OxyColors.White); } }
/// <summary> /// Export the graph to the specified 'bitmap' /// </summary> /// <param name="bitmap">Bitmap to write to</param> /// <param name="legendOutside">Put legend outside of graph?</param> public void Export(ref Bitmap bitmap, Rectangle r, bool legendOutside) { MemoryStream stream = new MemoryStream(); PngExporter pngExporter = new PngExporter(); pngExporter.Width = r.Width; pngExporter.Height = r.Height; pngExporter.Export(plot1.Model, stream); using (Graphics gfx = Graphics.FromImage(bitmap)) { Bitmap newBitmap = new Bitmap(stream); gfx.DrawImage(newBitmap, r); } }
private void OnExport() { _fileDialog.SaveFileDialog.Filter = "PNG|*.png"; _fileDialog.SaveFileDialog.Title = GradeChart.Title; if (_fileDialog.SaveFileDialog.ShowDialog() == true) { var pngExporter = new PngExporter { Width = 1920, Height = 1080, Background = OxyColors.White }; pngExporter.ExportToFile(GradeChart, _fileDialog.SaveFileDialog.FileName); } }
private void OnSaveClick(object sender, RoutedEventArgs e) { double width = this.AssociatedObject.ActualWidth; double height = this.AssociatedObject.ActualHeight; if (ImageWidth > 0) { width = ImageWidth; } if (ImageHeight > 0) { height = ImageHeight; } if (Scale > 0) { width = width * Scale; height = height * Scale; } var dlg = new SaveFileDialog { Filter = ".png files|*.png|.pdf files|*.pdf", DefaultExt = ".png" }; if (dlg.ShowDialog().Value) { FileName = dlg.FileName; } var ext = Path.GetExtension(FileName).ToLower(); switch (ext) { case ".png": PngExporter.Export(this.AssociatedObject.ActualModel, FileName, (int)width, (int)height, OxyColors.White); break; case ".pdf": using (var s = File.Create(FileName)) { PdfExporter.Export(this.AssociatedObject.ActualModel, s, width, height); } break; default: break; } }
public MemoryStream ExportPng(int width, int height) { MemoryStream imageStream = new MemoryStream(); var pngExporter = new PngExporter { Width = width, Height = height, Background = OxyColors.White }; pngExporter.Export(chart.ActualModel, imageStream); return(imageStream); }
public static Stream Save(this PlotModel plot) { var stream = new MemoryStream(); var pngExporter = new PngExporter { Width = 800, Height = 800, Background = OxyColors.White }; pngExporter.Export(plot, stream); stream.Position = 0; return(stream); }
/// <summary> /// Converts the plot model into a BitmapSource with the given size and resolution. /// </summary> /// <param name="model"></param> /// <param name="size"></param> /// <param name="resolution"></param> /// <returns></returns> public BitmapSource CreateImageHighRes(PlotModel model, Size size, double resolution) { var multiplier = (resolution / 96.0); var width = Math.Ceiling(size.Width * multiplier); var height = Math.Ceiling(size.Height * multiplier); var pngExporter = new PngExporter { Width = (int)width, Height = (int)height, Resolution = (int)resolution }; return(pngExporter.ExportToBitmap(model)); }
/// <summary>The export.</summary> /// <param name="plotModel">The plot model to export.</param> /// <param name="filePath">The output file path.</param> /// <param name="suggestedWidth">The suggested width.</param> /// <param name="suggestedHeight">The suggested height.</param> /// <param name="backgroundColor">The background color.</param> /// <param name="dpi">The DPI resolution.</param> public static void Export( PlotModel plotModel, string filePath, int suggestedWidth, int suggestedHeight, OxyColor backgroundColor, int dpi) { var upscaleFactor = dpi / 96.0; int width = (int)Math.Ceiling(suggestedWidth * upscaleFactor); int height = (int)Math.Ceiling(suggestedHeight * upscaleFactor); PngExporter.Export(plotModel, filePath, width, height, backgroundColor, dpi); }
public void ExportWithResolution(double factor) { var resolution = (int)(96 * factor); var plotModel = TestModels.CreateTestModel1(); var fileName = string.Format(CultureInfo.InvariantCulture, "PngExporterTests_ExportWithResolution_{0}dpi.png", resolution); var exporter = new PngExporter { Width = (int)(400 * factor), Height = (int)(300 * factor), Resolution = resolution }; using (var stream = File.OpenWrite(fileName)) { exporter.Export(plotModel, stream); } Assert.IsTrue(File.Exists(fileName)); PngAssert.AreEqual(Path.Combine("Baseline", fileName), fileName, fileName, Path.Combine("Diff", fileName)); }
public void TestGraph_Is_Created() { var plotModel = new PlotModel { Title = "Test Plot" }; plotModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)")); var pngExporter = new PngExporter { Width = 1280, Height = 720, Background = OxyColors.White }; pngExporter.ExportToFile(plotModel, $"{OutputPath}/test.png"); Assert.IsTrue(File.Exists($"{OutputPath}/test.png")); }
public void ExportPngAndCompareWithBaseline() { const string DestinationDirectory = "ExampleLibrary.Actual"; const string BaselineDirectory = "ExampleLibrary.Baseline"; const string DiffDirectory = "ExampleLibrary.Diff"; if (!Directory.Exists(BaselineDirectory)) { Directory.CreateDirectory(BaselineDirectory); } if (!Directory.Exists(DestinationDirectory)) { Directory.CreateDirectory(DestinationDirectory); } if (!Directory.Exists(DiffDirectory)) { Directory.CreateDirectory(DiffDirectory); } foreach (var example in ExampleLibrary.Examples.GetList()) { void ExportAndCompareToBaseline(PlotModel model, string fileName) { if (model == null) { return; } var baselinePath = Path.Combine(BaselineDirectory, fileName); var path = Path.Combine(DestinationDirectory, fileName); var diffpath = Path.Combine(DiffDirectory, fileName); PngExporter.Export(model, path, 800, 500); if (File.Exists(baselinePath)) { PngAssert.AreEqual(baselinePath, path, example.Title, diffpath); } else { File.Copy(path, baselinePath); } } ExportAndCompareToBaseline(example.PlotModel, CreateValidFileName($"{example.Category} - {example.Title}", ".png")); ExportAndCompareToBaseline(example.TransposedPlotModel, CreateValidFileName($"{example.Category} - {example.Title} - Transposed", ".png")); } }
/// <summary> /// 画像保存のイベントを受け取った時の処理 /// </summary> /// <param name="fn"></param> private void ChartSave(string fn) { string filename = FileName; if (FileName == "") { filename = fn; } if (filename == "") { var dlg = new SaveFileDialog { Filter = ".png files|*.png", DefaultExt = ".png" }; if (dlg.ShowDialog().Value) { filename = dlg.FileName; } } Plot plot = this.AssociatedObject as Plot; double width = plot.ActualWidth; double height = plot.ActualHeight; if (ImageWidth > 0) { width = ImageWidth; } if (ImageHeight > 0) { height = ImageHeight; } if (Scale > 0) { width = width * Scale; height = height * Scale; } if (filename != "") { var ext = Path.GetExtension(filename).ToLower(); if (ext == ".png") { PngExporter.Export(plot.ActualModel, filename, (int)width, (int)height, OxyColors.White); } } }
public void Export(string outputFolder, ref Dictionary <string, string> outputFiles) { string baseFilename = outputFolder + "/" + Herd.Utils.RemoveSpecialCharacters(name); //1st save in common formats: png and svg string fileName; //as png fileName = baseFilename + ".png"; var pngExporter = new PngExporter { Width = 600, Height = 400, Background = OxyColors.Transparent }; pngExporter.ExportToFile(Plot, fileName); //as svg fileName = baseFilename + ".svg"; var svgExporter = new OxyPlot.Wpf.SvgExporter { Width = 600, Height = 400 }; svgExporter.ExportToFile(Plot, fileName); //2nd save data from the model for importing fileName = baseFilename + Herd.Files.Extensions.PlotDataExtension; using (TextWriter writer = File.CreateText(fileName)) { writer.WriteLine("<" + XMLTags.PlotNodeTag + " " + XMLTags.nameAttribute + "=\"" + Herd.Utils.RemoveSpecialCharacters(name) + "\">"); foreach (OxyPlot.Series.LineSeries lineSeries in Plot.Series) { writer.WriteLine(" <" + XMLTags.LineSeriesTag + " " + XMLTags.nameAttribute + "=\"" + lineSeries.Title + "\">"); foreach (DataPoint dataPoint in lineSeries.Points) { writer.WriteLine(" <" + XMLTags.DataPointTag + ">"); writer.WriteLine(" <" + XMLTags.DataPointXTag + ">" + dataPoint.X + "</" + XMLTags.DataPointXTag + ">"); writer.WriteLine(" <" + XMLTags.DataPointYTag + ">" + dataPoint.Y + "</" + XMLTags.DataPointYTag + ">"); writer.WriteLine(" </" + XMLTags.DataPointTag + ">"); } writer.WriteLine(" </" + XMLTags.LineSeriesTag + ">"); } writer.WriteLine("</" + XMLTags.PlotNodeTag + ">"); string relPlotFilename = Herd.Utils.RemoveSpecialCharacters(name) + Herd.Files.Extensions.PlotDataExtension; outputFiles[relPlotFilename] = XMLTags.PlotNodeTag; } }
public static void saveToFile(string ime, PlotModel model) { var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); var fullName = Path.Combine(desktopFolder, ime); var fs = new FileStream(fullName, FileMode.Create); var size = Screen.Default; var pngExporter = new PngExporter { Width = size.Width, Height = size.Height, Background = OxyColors.White }; pngExporter.Export(model, fs); fs.Close(); }
public void Export() { if (Path.EndsWith(".png")) { var pngExporter = new PngExporter { Width = GraphWidth, Height = GraphHeight, Background = OxyColor.FromArgb( BackgroundColor.A, BackgroundColor.R, BackgroundColor.G, BackgroundColor.B) }; pngExporter.ExportToFile(MyModel, Path); } }
/// <summary> /// 导出按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Export_button_Click(object sender, EventArgs e) { try { var path = this.GetFilename(".png files|*.png", ".png"); if (path != null) { PngExporter.Export(plotView1.Model, path, 800, 500, Brushes.White); OpenContainingFolder(path); } } catch (Exception) { } }