Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.64 KB | None | 0 0
  1. using System.Drawing;
  2. using System.Threading;
  3. using System.Windows;
  4. using System.Windows.Forms;
  5. using Microsoft.Expression.Encoder.ScreenCapture;
  6.  
  7. namespace ScreenCapture
  8. {
  9.     /// <summary>
  10.     /// Interaction logic for MainWindow.xaml
  11.     /// </summary>
  12.     public partial class MainWindow : Window
  13.     {
  14.         /// <summary>
  15.         /// Screen capture job
  16.         /// </summary>
  17.         ScreenCaptureJob job;
  18.         System.Diagnostics.Stopwatch sw;
  19.  
  20.         public MainWindow()
  21.         {
  22.             job = new ScreenCaptureJob();
  23.             sw = new System.Diagnostics.Stopwatch();
  24.             InitializeComponent();
  25.         }
  26.  
  27.         /// <summary>
  28.         /// Checks if we are still capturing and if check if they want to cancel
  29.         /// </summary>
  30.         /// <param name="sender"></param>
  31.         /// <param name="e"></param>
  32.         private void OnClose(object sender, System.ComponentModel.CancelEventArgs e)
  33.         {
  34.             // checks if the job is running and if so prompts to continue
  35.             if (job.Status == RecordStatus.Running)
  36.             {
  37.                 MessageBoxResult result = System.Windows.MessageBox.Show("Capturing in Progress. Are You Sure You Want To Quit?", "Capturing", MessageBoxButton.YesNo);
  38.                 if (result == MessageBoxResult.No)
  39.                 {
  40.                     e.Cancel = true;
  41.                     return;
  42.                 }
  43.             }
  44.             job.Stop();
  45.             job.Dispose();
  46.            
  47.         }
  48.  
  49.         /// <summary>
  50.         /// Starts capturing job and thread
  51.         /// </summary>
  52.         /// <param name="sender"></param>
  53.         /// <param name="e"></param>
  54.         private void RecButton_Checked(object sender, RoutedEventArgs e)
  55.         {
  56.             System.Drawing.Size monitorSize = SystemInformation.PrimaryMonitorSize;
  57.             Rectangle capRect = new Rectangle(0, 0, monitorSize.Width, monitorSize.Height);
  58.  
  59.             job.CaptureRectangle = capRect;
  60.             job.OutputPath = @"C:\output\ScreenCap";
  61.             sw.Start();
  62.             job.Start();
  63.             //job.Statistics.
  64.         }
  65.  
  66.         /// <summary>
  67.         /// Stops capturing job and thread
  68.         /// </summary>
  69.         /// <param name="sender"></param>
  70.         /// <param name="e"></param>
  71.         private void RecButton_UnChecked(object sender, RoutedEventArgs e)
  72.         {
  73.             int frames = job.Statistics.FrameCount;
  74.  
  75.             job.Stop();
  76.             sw.Stop();
  77.  
  78.             System.Windows.MessageBox.Show("Frames: " + frames.ToString() + "\nSpeed: " + (((double)sw.ElapsedMilliseconds) / frames).ToString() + " ms");
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement