public void SaveXps() { var path = this.GetFilename(".xps files|*.xps", ".xps"); if (path != null) { XpsExporter.Export(this.Model, path, this.Plot.ActualWidth, this.Plot.ActualHeight, this.Model.Background); OpenContainingFolder(path); } }
public void Print() { XpsExporter.Print(this.Model, this.Plot.ActualWidth, this.Plot.ActualHeight); }
private void ImageExportToFile() { GraphControl control = graphControl; // check if the rectangular region or the whole viewport should be printed bool useRect = (bool)handler.GetValue(OUTPUT, EXPORT_RECTANGLE); RectD bounds = useRect ? exportRect.ToRectD() : control.Viewport; // get the format string formatChoice = (string)Handler.GetValue(OUTPUT, FORMAT); string format = Formats[formatChoice]; // check whether decorations (selection, handles, ...) should be hidden bool hide = (bool)handler.GetValue(OUTPUT, HIDE_DECORATIONS); if (hide) { // if so, create a new graph control with the same graph control = new GraphControl { Graph = graphControl.Graph, FlowDirection = graphControl.FlowDirection }; } IImageExporter exporter; ContextConfigurator config = GetConfig(bounds, !useRect); if (format.Equals("XPS")) { // create the exporter XpsExporter emfImageExporter = new XpsExporter(config); exporter = emfImageExporter; saveFileDialog.Reset(); saveFileDialog.Filter = "XPS files (*.xps)|*.xps"; if (saveFileDialog.ShowDialog(this) == true) { string fileName = saveFileDialog.FileName; if (File.Exists(fileName)) { File.Delete(fileName); } using (FileStream stream = new FileStream(fileName, FileMode.CreateNew, FileAccess.ReadWrite)) { exporter.Export(control, stream); } } } else { var transparentBackground = (bool)Handler.GetValue(PNG, TRANSPARENT); // create the exporter PixelImageExporter pixelImageExport = new PixelImageExporter(config); AddExportParameters(pixelImageExport, format); pixelImageExport.OutputFormat = format; // check if the format is transparent PNG if ((!format.Equals("image/png") || !transparentBackground)) { // if not, set the background color pixelImageExport.Background = control.Background ?? Brushes.White; } exporter = pixelImageExport; saveFileDialog.Reset(); saveFileDialog.Filter = format + "|*." + format.Substring(6); if (saveFileDialog.ShowDialog(this) == true) { FileStream stream = new FileStream(saveFileDialog.FileName, FileMode.Create, FileAccess.Write); exporter.Export(control, stream); stream.Flush(); stream.Close(); } } }
private ImageSource ImageExport() { GraphControl control = graphControl; // check if the rectangular region or the whole viewport should be exported bool useRect = (bool)handler.GetValue(OUTPUT, EXPORT_RECTANGLE); RectD bounds = useRect ? exportRect.ToRectD() : control.Viewport; // get the format string formatChoice = (string)Handler.GetValue(OUTPUT, FORMAT); string format = Formats[formatChoice]; // check whether decorations (selection, handles, ...) should be hidden bool hide = (bool)handler.GetValue(OUTPUT, HIDE_DECORATIONS); if (hide) { // if so, create a new graph control with the same graph control = new GraphControl { Graph = graphControl.Graph, FlowDirection = graphControl.FlowDirection, Background = graphControl.Background, Projection = graphControl.Projection }; } IImageExporter exporter; ContextConfigurator config = GetConfig(bounds, !useRect); var transparentBackground = (bool)Handler.GetValue(PNG, TRANSPARENT); if (format.Equals("XPS")) { // create the exporter XpsExporter xpsExporter = new XpsExporter(config); string tempFileName = Path.GetTempFileName(); using (var fileStream = new FileStream(tempFileName, FileMode.Create, FileAccess.ReadWrite)) { xpsExporter.Export(control, fileStream); } documentViewer.Visibility = Visibility.Visible; previewCanvas.Visibility = Visibility.Hidden; documentViewer.Document = new XpsDocument(tempFileName, FileAccess.Read).GetFixedDocumentSequence(); return(null); } else { // create the exporter PixelImageExporter pixelImageExport = new PixelImageExporter(config); AddExportParameters(pixelImageExport, format); pixelImageExport.OutputFormat = format; // check if the format is transparent PNG if ((!format.Equals("image/png") || !transparentBackground)) { // if not, set the background color pixelImageExport.Background = control.Background ?? Brushes.White; } exporter = pixelImageExport; var memoryStream = new MemoryStream(); try { exporter.Export(control, memoryStream); // reset the stream memoryStream.Position = 0; // and read back the image for display var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = memoryStream; bitmapImage.EndInit(); if (previewCanvas.RootGroup.First != null) { previewCanvas.RootGroup.First.Remove(); } documentViewer.Visibility = Visibility.Hidden; previewCanvas.Visibility = Visibility.Visible; var image = new Image { Source = bitmapImage, Width = bitmapImage.Width, Height = bitmapImage.Height }; image.SetCanvasArrangeRect(new Rect(0, 0, image.Width, image.Height)); previewCanvas.RootGroup.AddChild(image, CanvasObjectDescriptors.Visual); previewCanvas.ContentRect = new RectD(0, 0, bitmapImage.Width, bitmapImage.Height).GetEnlarged(20); return(bitmapImage); } catch (IOException exception) { MessageBox.Show(exception.Message, "I/O Error", MessageBoxButton.OK); return(null); } } }
/// <summary> /// Prints the specified plot model. /// </summary> /// <param name="model">The model.</param> /// <param name="width">The width (using the actual media width if set to NaN).</param> /// <param name="height">The height (using the actual media height if set to NaN).</param> public static void Print(IPlotModel model, double width, double height) { var exporter = new XpsExporter { Width = width, Height = height, Background = model.Background }; exporter.Print(model); }
/// <summary> /// Exports the specified <see cref="PlotModel" /> to the specified <see cref="Stream" />. /// </summary> /// <param name="model">The model.</param> /// <param name="stream">The stream.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> public static void Export(IPlotModel model, Stream stream, double width, double height) { var exporter = new XpsExporter { Width = width, Height = height }; exporter.Export(model, stream); }