Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Drawing;
- using System.Threading;
- using System.Windows;
- using System.Windows.Forms;
- using Microsoft.Expression.Encoder.ScreenCapture;
- namespace ScreenCapture
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- /// <summary>
- /// Screen capture job
- /// </summary>
- ScreenCaptureJob job;
- System.Diagnostics.Stopwatch sw;
- public MainWindow()
- {
- job = new ScreenCaptureJob();
- sw = new System.Diagnostics.Stopwatch();
- InitializeComponent();
- }
- /// <summary>
- /// Checks if we are still capturing and if check if they want to cancel
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnClose(object sender, System.ComponentModel.CancelEventArgs e)
- {
- // checks if the job is running and if so prompts to continue
- if (job.Status == RecordStatus.Running)
- {
- MessageBoxResult result = System.Windows.MessageBox.Show("Capturing in Progress. Are You Sure You Want To Quit?", "Capturing", MessageBoxButton.YesNo);
- if (result == MessageBoxResult.No)
- {
- e.Cancel = true;
- return;
- }
- }
- job.Stop();
- job.Dispose();
- }
- /// <summary>
- /// Starts capturing job and thread
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RecButton_Checked(object sender, RoutedEventArgs e)
- {
- System.Drawing.Size monitorSize = SystemInformation.PrimaryMonitorSize;
- Rectangle capRect = new Rectangle(0, 0, monitorSize.Width, monitorSize.Height);
- job.CaptureRectangle = capRect;
- job.OutputPath = @"C:\output\ScreenCap";
- sw.Start();
- job.Start();
- //job.Statistics.
- }
- /// <summary>
- /// Stops capturing job and thread
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RecButton_UnChecked(object sender, RoutedEventArgs e)
- {
- int frames = job.Statistics.FrameCount;
- job.Stop();
- sw.Stop();
- System.Windows.MessageBox.Show("Frames: " + frames.ToString() + "\nSpeed: " + (((double)sw.ElapsedMilliseconds) / frames).ToString() + " ms");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement