예제 #1
0
        private void SaveGraphButtonClick(object clickSender, RoutedEventArgs clickE)
        {
            try
            {
                var dialog = new SaveFileDialog()
                {
                    Title  = "ベンチマーク結果グラフ画像を保存",
                    Filter = "SVG (*.svg)|*.svg|BMP (*.bmp)|*.bmp|PNG (*.png)|*.png|JPEG (*.jpg;*.jpeg;*.jpe;*.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif"
                };
                dialog.FileOk += (object sender, CancelEventArgs e) =>
                {
                    var d = (SaveFileDialog)sender;
                    using (var saveFile = d.OpenFile())
                    {
                        if (1 == d.FilterIndex)
                        {
                            var plot        = this.FindName("BenchmarkGraph") as OxyPlot.Wpf.Plot;
                            var svgExporter = new OxyPlot.SvgExporter {
                                Width = plot.ActualWidth, Height = plot.ActualHeight
                            };
                            svgExporter.Export(plot.ActualModel, saveFile);
                        }
                        else
                        {
                            ImageFormat fmt;
                            switch (d.FilterIndex)
                            {
                            case 2: fmt = ImageFormat.Bmp; break;

                            case 3: fmt = ImageFormat.Png; break;

                            case 4: fmt = ImageFormat.Jpeg; break;

                            default: fmt = ImageFormat.Png; break;
                            }
                            this.windowCapture_.Capture().Save(saveFile, fmt);
                        }
                    }
                };
                dialog.ShowDialog();
            }
            catch (Exception ex)
            {
                this.benchmarkResultManager_.NotifyError(ex.ToString());
            }
        }
예제 #2
0
        public async Task <IActionResult> Get(string format, string source, int width = 800, int height = 400)
        {
            var options = ScriptOptions.Default.WithReferences(typeof(OxyPlot.PlotModel).Assembly)
                          .WithImports("System", "OxyPlot", "OxyPlot.Axes", "OxyPlot.Series", "OxyPlot.Annotations");

            var result = await CSharpScript.EvaluateAsync(source, options);

            var model = result as OxyPlot.PlotModel;

            var contentType = this.Request.HasFormContentType ? this.Request.ContentType : "image/png";

            if (format != null && format == "svg")
            {
                contentType = "image/svg+xml";
            }

            switch (contentType)
            {
            case "image/svg+xml":
            {
                var e = new OxyPlot.SvgExporter {
                    Width = width, Height = height
                };
                var svg = e.ExportToString(model);
                return(this.Content(svg, "image/svg+xml"));
            }

            default:
            {
                var p = new OxyPlot.Core.Drawing.PngExporter {
                    Width = width, Height = height
                };
                var stream = new MemoryStream();
                p.Export(model, stream);
                stream.Position = 0;
                return(this.File(stream, "image/png"));
            }
            }
        }