private void ExportToImageButton_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.SaveFileDialog fileDialog; fileDialog = new Microsoft.Win32.SaveFileDialog(); fileDialog.DefaultExt = "png"; fileDialog.Filter = "Png files(*.png)|*.png"; fileDialog.Title = "Select output png file"; fileDialog.FileName = "Plot3D.png"; if (fileDialog.ShowDialog() ?? false) { BitmapSource plotImage = Camera1.RenderToBitmap(backgroundBrush: MainGrid.Background); // We are calling RenderToBitmap, but it is possible to specify many parameters - background brush, dpi, custom image size and antialiasing level if (plotImage != null) { using (var fileStream = new System.IO.FileStream(fileDialog.FileName, System.IO.FileMode.Create)) { BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(plotImage)); encoder.Save(fileStream); } } } }
private void ExportButton_OnClick(object sender, RoutedEventArgs e) { string fileName; if (_rootModel3D == null) { return; } if (_fileName != null) { fileName = System.IO.Path.ChangeExtension(_fileName, ".wpf3d"); } else { fileName = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\model3D.wpf3d"; } var thumbnail = Camera1.RenderToBitmap(128, 128, 4); var wpf3DFileExportUserControl = new Wpf3DFileExportUserControl { FileName = fileName, RootModel = _rootModel3D, Camera = Camera1, Thumbnail = thumbnail, SourceFileName = _fileName, Margin = new Thickness(10, 0, 10, 0) }; var window = new Window { Width = 450, Height = 595, Title = "Export 3D scene", Content = wpf3DFileExportUserControl, Owner = Window.GetWindow(this), WindowStartupLocation = WindowStartupLocation.CenterOwner }; wpf3DFileExportUserControl.SaveButtonClicked += delegate(object o, EventArgs args) { window.Close(); }; wpf3DFileExportUserControl.CancelButtonClicked += delegate(object o, EventArgs args) { window.Close(); }; window.ShowDialog(); }
private void ExportToImageButton_Click(object sender, RoutedEventArgs e) { var fileDialog = new Microsoft.Win32.SaveFileDialog { DefaultExt = "png", Filter = "Png files(*.png)|*.png", Title = "Select output png file", FileName = "Plot3D.png" }; if (fileDialog.ShowDialog() ?? false) { // NOTE: To get superior image quality with super-smooth 3D lines use Ab3d.DXEngine and call DXViewportView.RenderToBitmap method instead or camera.RenderToBitmap BitmapSource plotImage = Camera1.RenderToBitmap(customWidth: 1920, customHeight: 1200, antialiasingLevel: 4, backgroundBrush: MainGrid.Background); if (plotImage != null) { using (var fileStream = new System.IO.FileStream(fileDialog.FileName, System.IO.FileMode.Create)) { BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(plotImage)); encoder.Save(fileStream); } // Open the saved image in the default image viewer // For Core3 we need to set UseShellExecute to true (see https://github.com/dotnet/corefx/issues/33714) var processStartInfo = new ProcessStartInfo { FileName = fileDialog.FileName, UseShellExecute = true }; Process.Start(processStartInfo); } } }