Ejemplo n.º 1
0
        /// <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));
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
        /// <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);
            }
        }
Ejemplo n.º 6
0
 /// <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()));
 }
Ejemplo n.º 7
0
        /// <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));
        }
Ejemplo n.º 8
-1
 /// <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);
 }
Ejemplo n.º 9
-1
 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);
 }
Ejemplo n.º 10
-2
 /// <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);
 }