Ejemplo n.º 1
0
 private void ButtonStartStop_Click(object sender, EventArgs e)
 {
     if (_isRunning)
     {
         // Stop capturing
         _timer.Stop();
         buttonStartStop.Text = "Start";
         panelForm.Enabled    = true;
         _isRunning           = false;
     }
     else
     {
         // Start capturing
         ImageProcessor.ProcessInfo info = new ImageProcessor.ProcessInfo();
         if (checkBoxAbsoluteSize.Checked)
         {
             info.useAbsoluteSize = true;
             info.size            = _absoluteSize;
         }
         else
         {
             info.useAbsoluteSize = false;
             if (!double.TryParse(textBoxScale.Text, out info.scale))
             {
                 MessageBox.Show("Scale must be a real number");
                 return;
             }
         }
         int interval;
         if (!int.TryParse(textBoxInterval.Text, out interval))
         {
             MessageBox.Show("Interval must be an integer");
             return;
         }
         string dirPath = textBoxSaveDir.Text;
         if (!Directory.Exists(dirPath))
         {
             MessageBox.Show("Save directory path does not exist");
             return;
         }
         _timer = CreateCaptueringTimer(info, interval, dirPath);
         _timer.Start();
         buttonStartStop.Text = "Stop";
         panelForm.Enabled    = false;
         _isRunning           = true;
     }
 }
Ejemplo n.º 2
0
        private Timer CreateCaptueringTimer(ImageProcessor.ProcessInfo info, int interval, string dirPath)
        {
            Timer           timer     = new Timer();
            ImageProcessor  processor = new ImageProcessor(info);
            DesktopCapturer capturer  = new DesktopCapturer(processor);
            ImageFormat     format    = (ImageFormat)comboBoxFormat.SelectedItem;

            timer.Interval = interval;
            timer.Tick    += new EventHandler((sender, e) =>
            {
                // ファイル名はミリ秒までの現在時刻
                string fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + FormatExtention(format);
                string path     = Path.Combine(dirPath, fileName);

                capturer.CaptureAndSaveDesktop(path, format);
            });
            return(timer);
        }