void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { ((System.Timers.Timer)sender).Stop(); Dispatcher.Invoke((Action)delegate { string filename = System.IO.Path.Combine( _lastSaveDir ?? Environment.GetFolderPath(Environment.SpecialFolder.Desktop), System.IO.Path.GetRandomFileName() + ".bmp"); try { using (System.Drawing.Image image = _capMgr.CreateImage()) { CapturePreviewWindow prev = new CapturePreviewWindow(); prev.CaptureFilename = filename; // Create a WPF-compatibale image source from a System.Drawing.Bitmap BitmapSource source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(((System.Drawing.Bitmap)image).GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); prev.image1.Source = source; bool? dr = prev.ShowDialog(); if (dr.HasValue && dr.Value) { filename = prev.CaptureFilename; _lastSaveDir = System.IO.Path.GetDirectoryName(filename); image.Save(filename); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Visibility = System.Windows.Visibility.Visible; Focus(); } }); }
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { ((System.Timers.Timer)sender).Stop(); Dispatcher.Invoke((Action) delegate { string filename = System.IO.Path.Combine( _lastSaveDir ?? Environment.GetFolderPath(Environment.SpecialFolder.Desktop), System.IO.Path.GetRandomFileName() + ".bmp"); try { using (System.Drawing.Image image = _capMgr.CreateImage()) { CapturePreviewWindow prev = new CapturePreviewWindow(); prev.CaptureFilename = filename; // Create a WPF-compatibale image source from a System.Drawing.Bitmap BitmapSource source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(((System.Drawing.Bitmap)image).GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); prev.image1.Source = source; bool?dr = prev.ShowDialog(); if (dr.HasValue && dr.Value) { filename = prev.CaptureFilename; _lastSaveDir = System.IO.Path.GetDirectoryName(filename); image.Save(filename); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Visibility = System.Windows.Visibility.Visible; Focus(); } }); }