/// <summary> /// Handles the Click event of the SaveFrameButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void SaveFrameButton_Click(object sender, RoutedEventArgs e) { var dialog = new SaveFileDialog(); dialog.Filter = "Portable Network Graphics (*.png)|*.png"; dialog.DefaultExt = "png"; dialog.AddExtension = true; var result = dialog.ShowDialog(); if (result.HasValue == false || result.Value == false) { return; } if (File.Exists(dialog.FileName)) { File.Delete(dialog.FileName); } using (var fileStream = File.OpenWrite(dialog.FileName)) { var encoder = new PngBitmapEncoder(); var bitmap = MediaEl.GetCurrentFrame(); encoder.Frames.Add(BitmapFrame.Create(bitmap)); encoder.Save(fileStream); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { Microsoft.Win32.SaveFileDialog saveDlg = new Microsoft.Win32.SaveFileDialog(); saveDlg.Filter = "Bitmap (*.bmp)|*.bmp"; saveDlg.DefaultExt = "bmp"; saveDlg.AddExtension = true; Nullable <bool> result = saveDlg.ShowDialog(); if (result == true) { using (FileStream fileStream = new FileStream(saveDlg.FileName, FileMode.OpenOrCreate)) { PngBitmapEncoder encoder = new PngBitmapEncoder(); WriteableBitmap wBMP = MediaEl.GetCurrentFrame(); encoder.Frames.Add(BitmapFrame.Create(wBMP)); encoder.Save(fileStream); } } }