using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PaintDotNet.Base.CommTool;
using PaintDotNet.Camera;
using PaintDotNet.Camera;
using PaintDotNet.SystemLayer;
namespace PaintDotNet.ImageCollect
{
internal class CameraTimedShooting : FloatingToolForm
{
#region
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeLanguageText()
{
this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
this.btnStop.Text = PdnResources.GetString("Menu.stop.text");
this.btnStart.Text = PdnResources.GetString("Menu.Started.text");
this.groupBox2.Text = PdnResources.GetString("Menu.imagecapture.timelapse.Timeintervalsetting.text");
this.rdoTimeLapse.Text = PdnResources.GetString("Menu.timeinterval.text");
this.rdoSpeedFast.Text = PdnResources.GetString("Menu.imagecapture.timelapse.Fastestspeed.text");
this.groupBox3.Text = PdnResources.GetString("Menu.imagecapture.timelapse.Durationsetting.text");
this.rdoDuration.Text = PdnResources.GetString("Menu.imagecapture.timelapse.duration.text");
this.btnCalculate.Text = PdnResources.GetString("Menu.compute.text");
this.rdoTimes.Text = "#" + PdnResources.GetString("Menu.imagecapture.timelapse.cycle.text");
this.rdoMax.Text = PdnResources.GetString("Menu.imagecapture.timelapse.Maxduration.text");
this.groupBox4.Text = PdnResources.GetString("Menu.imagecapture.timelapse.SaveSettings.text");
this.btnModifyPath.Text = PdnResources.GetString("Menu.alter.text");
this.label2.Text = PdnResources.GetString("Menu.Nameprefix.text") + ":";
this.label1.Text = PdnResources.GetString("Menu.saveroute.text") + ":";
this.chkSave.Text = PdnResources.GetString("Menu.imagecapture.timelapse.Savetoharddrive.text");
this.Text = PdnResources.GetString("Menu.ImageCollection.TimedShooting.Text");
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnStop = new System.Windows.Forms.Button();
this.btnStart = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.cmbUnits = new System.Windows.Forms.ComboBox();
this.nudTimeLapse = new System.Windows.Forms.NumericUpDown();
this.rdoTimeLapse = new System.Windows.Forms.RadioButton();
this.rdoSpeedFast = new System.Windows.Forms.RadioButton();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.cmbDuration = new System.Windows.Forms.ComboBox();
this.nudDuration = new System.Windows.Forms.NumericUpDown();
this.rdoDuration = new System.Windows.Forms.RadioButton();
this.btnCalculate = new System.Windows.Forms.Button();
this.nudTimes = new System.Windows.Forms.NumericUpDown();
this.rdoTimes = new System.Windows.Forms.RadioButton();
this.rdoMax = new System.Windows.Forms.RadioButton();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.btnModifyPath = new System.Windows.Forms.Button();
this.txtPrefix = new System.Windows.Forms.TextBox();
this.txtSavePath = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.chkSave = new System.Windows.Forms.CheckBox();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudTimeLapse)).BeginInit();
this.groupBox3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudDuration)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudTimes)).BeginInit();
this.groupBox4.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.btnStop);
this.groupBox1.Controls.Add(this.btnStart);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(348, 66);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "操作";
//
// btnStop
//
this.btnStop.Enabled = false;
this.btnStop.Location = new System.Drawing.Point(258, 22);
this.btnStop.Name = "btnStop";
this.btnStop.Size = new System.Drawing.Size(68, 30);
this.btnStop.TabIndex = 3;
this.btnStop.Text = "停止";
this.btnStop.UseVisualStyleBackColor = true;
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
//
// btnStart
//
this.btnStart.Location = new System.Drawing.Point(184, 22);
this.btnStart.Name = "btnStart";
this.btnStart.Size = new System.Drawing.Size(68, 30);
this.btnStart.TabIndex = 2;
this.btnStart.Text = "开始";
this.btnStart.UseVisualStyleBackColor = true;
this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.cmbUnits);
this.groupBox2.Controls.Add(this.nudTimeLapse);
this.groupBox2.Controls.Add(this.rdoTimeLapse);
this.groupBox2.Controls.Add(this.rdoSpeedFast);
this.groupBox2.Location = new System.Drawing.Point(12, 89);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(348, 100);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "时间间隔设置";
//
// cmbUnits
//
this.cmbUnits.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbUnits.FormattingEnabled = true;
this.cmbUnits.Location = new System.Drawing.Point(253, 61);
this.cmbUnits.Name = "cmbUnits";
this.cmbUnits.Size = new System.Drawing.Size(73, 20);
this.cmbUnits.TabIndex = 3;
//
// nudTimeLapse
//
this.nudTimeLapse.Location = new System.Drawing.Point(147, 62);
this.nudTimeLapse.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.nudTimeLapse.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.nudTimeLapse.Name = "nudTimeLapse";
this.nudTimeLapse.Size = new System.Drawing.Size(84, 21);
this.nudTimeLapse.TabIndex = 2;
this.nudTimeLapse.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// rdoTimeLapse
//
this.rdoTimeLapse.AutoSize = true;
this.rdoTimeLapse.Checked = true;
this.rdoTimeLapse.Location = new System.Drawing.Point(16, 64);
this.rdoTimeLapse.Name = "rdoTimeLapse";
this.rdoTimeLapse.Size = new System.Drawing.Size(71, 16);
this.rdoTimeLapse.TabIndex = 1;
this.rdoTimeLapse.TabStop = true;
this.rdoTimeLapse.Text = "时间间隔";
this.rdoTimeLapse.UseVisualStyleBackColor = true;
//
// rdoSpeedFast
//
this.rdoSpeedFast.AutoSize = true;
this.rdoSpeedFast.Location = new System.Drawing.Point(16, 34);
this.rdoSpeedFast.Name = "rdoSpeedFast";
this.rdoSpeedFast.Size = new System.Drawing.Size(71, 16);
this.rdoSpeedFast.TabIndex = 0;
this.rdoSpeedFast.Text = "最快速度";
this.rdoSpeedFast.UseVisualStyleBackColor = true;
this.rdoSpeedFast.CheckedChanged += new System.EventHandler(this.rdoSpeedFast_CheckedChanged);
//
// groupBox3
//
this.groupBox3.Controls.Add(this.cmbDuration);
this.groupBox3.Controls.Add(this.nudDuration);
this.groupBox3.Controls.Add(this.rdoDuration);
this.groupBox3.Controls.Add(this.btnCalculate);
this.groupBox3.Controls.Add(this.nudTimes);
this.groupBox3.Controls.Add(this.rdoTimes);
this.groupBox3.Controls.Add(this.rdoMax);
this.groupBox3.Location = new System.Drawing.Point(12, 205);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(348, 148);
this.groupBox3.TabIndex = 2;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "持续时间设置";
//
// cmbDuration
//
this.cmbDuration.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbDuration.FormattingEnabled = true;
this.cmbDuration.Location = new System.Drawing.Point(253, 106);
this.cmbDuration.Name = "cmbDuration";
this.cmbDuration.Size = new System.Drawing.Size(73, 20);
this.cmbDuration.TabIndex = 7;
//
// nudDuration
//
this.nudDuration.DecimalPlaces = 2;
this.nudDuration.Increment = new decimal(new int[] {
1,
0,
0,
131072});
this.nudDuration.Location = new System.Drawing.Point(147, 107);
this.nudDuration.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.nudDuration.Minimum = new decimal(new int[] {
1,
0,
0,
131072});
this.nudDuration.Name = "nudDuration";
this.nudDuration.Size = new System.Drawing.Size(84, 21);
this.nudDuration.TabIndex = 6;
this.nudDuration.Value = new decimal(new int[] {
1,
0,
0,
131072});
//
// rdoDuration
//
this.rdoDuration.AutoSize = true;
this.rdoDuration.Location = new System.Drawing.Point(16, 106);
this.rdoDuration.Name = "rdoDuration";
this.rdoDuration.Size = new System.Drawing.Size(71, 16);
this.rdoDuration.TabIndex = 5;
this.rdoDuration.Text = "持续时间";
this.rdoDuration.UseVisualStyleBackColor = true;
//
// btnCalculate
//
this.btnCalculate.Location = new System.Drawing.Point(253, 60);
this.btnCalculate.Name = "btnCalculate";
this.btnCalculate.Size = new System.Drawing.Size(73, 27);
this.btnCalculate.TabIndex = 4;
this.btnCalculate.Text = "计算";
this.btnCalculate.UseVisualStyleBackColor = true;
this.btnCalculate.Click += new System.EventHandler(this.btnCalculate_Click);
//
// nudTimes
//
this.nudTimes.Location = new System.Drawing.Point(147, 62);
this.nudTimes.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.nudTimes.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.nudTimes.Name = "nudTimes";
this.nudTimes.Size = new System.Drawing.Size(84, 21);
this.nudTimes.TabIndex = 3;
this.nudTimes.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// rdoTimes
//
this.rdoTimes.AutoSize = true;
this.rdoTimes.Checked = true;
this.rdoTimes.Location = new System.Drawing.Point(16, 68);
this.rdoTimes.Name = "rdoTimes";
this.rdoTimes.Size = new System.Drawing.Size(53, 16);
this.rdoTimes.TabIndex = 2;
this.rdoTimes.TabStop = true;
this.rdoTimes.Text = "#循环";
this.rdoTimes.UseVisualStyleBackColor = true;
//
// rdoMax
//
this.rdoMax.AutoSize = true;
this.rdoMax.Location = new System.Drawing.Point(16, 34);
this.rdoMax.Name = "rdoMax";
this.rdoMax.Size = new System.Drawing.Size(95, 16);
this.rdoMax.TabIndex = 1;
this.rdoMax.Text = "最大持续时间";
this.rdoMax.UseVisualStyleBackColor = true;
this.rdoMax.CheckedChanged += new System.EventHandler(this.rdoMax_CheckedChanged);
//
// groupBox4
//
this.groupBox4.Controls.Add(this.btnModifyPath);
this.groupBox4.Controls.Add(this.txtPrefix);
this.groupBox4.Controls.Add(this.txtSavePath);
this.groupBox4.Controls.Add(this.label2);
this.groupBox4.Controls.Add(this.label1);
this.groupBox4.Controls.Add(this.chkSave);
this.groupBox4.Location = new System.Drawing.Point(12, 368);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(348, 138);
this.groupBox4.TabIndex = 3;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "保存设置";
//
// btnModifyPath
//
this.btnModifyPath.Location = new System.Drawing.Point(253, 69);
this.btnModifyPath.Name = "btnModifyPath";
this.btnModifyPath.Size = new System.Drawing.Size(73, 25);
this.btnModifyPath.TabIndex = 5;
this.btnModifyPath.Text = "更改";
this.btnModifyPath.UseVisualStyleBackColor = true;
this.btnModifyPath.Click += new System.EventHandler(this.btnModifyPath_Click);
//
// txtPrefix
//
this.txtPrefix.Location = new System.Drawing.Point(101, 100);
this.txtPrefix.Name = "txtPrefix";
this.txtPrefix.Size = new System.Drawing.Size(141, 21);
this.txtPrefix.TabIndex = 4;
//
// txtSavePath
//
this.txtSavePath.Location = new System.Drawing.Point(101, 69);
this.txtSavePath.Name = "txtSavePath";
this.txtSavePath.ReadOnly = true;
this.txtSavePath.Size = new System.Drawing.Size(141, 21);
this.txtSavePath.TabIndex = 3;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(13, 106);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(65, 12);
this.label2.TabIndex = 2;
this.label2.Text = "名称前缀:";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(13, 72);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(65, 12);
this.label1.TabIndex = 1;
this.label1.Text = "保存路径:";
//
// chkSave
//
this.chkSave.AutoSize = true;
this.chkSave.Checked = true;
this.chkSave.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkSave.Location = new System.Drawing.Point(16, 34);
this.chkSave.Name = "chkSave";
this.chkSave.Size = new System.Drawing.Size(84, 16);
this.chkSave.TabIndex = 0;
this.chkSave.Text = "保存到硬盘";
this.chkSave.UseVisualStyleBackColor = true;
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 50;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// CameraTimedShooting
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(378, 518);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "CameraTimedShooting";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "定时拍摄";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.CameraTimedShooting_FormClosing);
this.Load += new System.EventHandler(this.CameraTimedShooting_Load);
this.Controls.SetChildIndex(this.groupBox1, 0);
this.Controls.SetChildIndex(this.groupBox2, 0);
this.Controls.SetChildIndex(this.groupBox3, 0);
this.Controls.SetChildIndex(this.groupBox4, 0);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudTimeLapse)).EndInit();
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudDuration)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudTimes)).EndInit();
this.groupBox4.ResumeLayout(false);
this.groupBox4.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button btnStop;
private System.Windows.Forms.Button btnStart;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.ComboBox cmbUnits;
private System.Windows.Forms.NumericUpDown nudTimeLapse;
private System.Windows.Forms.RadioButton rdoTimeLapse;
private System.Windows.Forms.RadioButton rdoSpeedFast;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.ComboBox cmbDuration;
private System.Windows.Forms.NumericUpDown nudDuration;
private System.Windows.Forms.RadioButton rdoDuration;
private System.Windows.Forms.Button btnCalculate;
private System.Windows.Forms.NumericUpDown nudTimes;
private System.Windows.Forms.RadioButton rdoTimes;
private System.Windows.Forms.RadioButton rdoMax;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Button btnModifyPath;
private System.Windows.Forms.TextBox txtPrefix;
private System.Windows.Forms.TextBox txtSavePath;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.CheckBox chkSave;
#endregion
///
/// 时间间隔单位
///
private string[] m_timeUnitsArray = new string[] { PdnResources.GetString("Menu.second.text"), PdnResources.GetString("Menu.millisecond.text") };
private string m_filePath = "";
private string m_fileTempPath = Application.StartupPath + "\\TimedShootTemp";
private string m_fileName;
///
/// 时间间隔 (毫秒)
///
private int m_timeLag;
// 循环次数
private int m_times = 0;
// 持续时间 (毫秒)
private int m_duration = 0;
private Timer timer1;
private AppWorkspace m_appWorkspace;
public CameraTimedShooting(AppWorkspace workspace)
{
m_appWorkspace = workspace;
InitializeComponent();
InitializeLanguageText();
InitializeControlData();
this.Load += (s, e) =>
{
m_filePath = Settings.CurrentUser.GetString("CameraTimedShootingPath", "");
txtSavePath.Text = m_filePath;
txtPrefix.Text = Settings.CurrentUser.GetString("CameraTimedShootingPrefix", "");
};
this.FormClosing += (s, e) =>
{
Settings.CurrentUser.SetString("CameraTimedShootingPath", txtSavePath.Text);
Settings.CurrentUser.SetString("CameraTimedShootingPrefix", txtPrefix.Text);
};
}
///
/// 设置下拉等数据源
///
private void InitializeControlData()
{
this.cmbUnits.Items.Add(m_timeUnitsArray[0]);
this.cmbUnits.SelectedIndex = 0;
this.cmbDuration.Items.Add(m_timeUnitsArray[0]);
this.cmbDuration.SelectedIndex = 0;
this.txtSavePath.Text = m_filePath;
}
private void btnModifyPath_Click(object sender, EventArgs e)
{
FolderBrowserDialog folderBroeser = new FolderBrowserDialog();
if (folderBroeser.ShowDialog() == DialogResult.OK)
{
m_filePath = folderBroeser.SelectedPath;
txtSavePath.Text = m_filePath;
}
}
private void btnCalculate_Click(object sender, EventArgs e)
{
calculate();
}
private void calculate()
{
if (rdoTimes.Checked)
{
m_times = Convert.ToInt32(nudTimes.Value);
m_duration = m_timeLag * m_times;
if (m_duration >= 1000)
{
nudDuration.Value = m_duration / 1000;
this.cmbDuration.SelectedIndex = 0;
}
else
{
nudDuration.Value = m_duration;
this.cmbDuration.SelectedIndex = 1;
}
}
else if (rdoDuration.Checked)
{
int tmpLapse = 1;
if (cmbDuration.SelectedItem.Equals(PdnResources.GetString("Menu.second.text")))
{
tmpLapse = 1000;
}
m_duration = (int)(nudDuration.Value * tmpLapse);
m_times = m_duration / m_timeLag;
if (m_times <= 0)
{
m_times = 1;
}
nudTimes.Value = m_times;
}
}
private void rdoMax_CheckedChanged(object sender, EventArgs e)
{
updateBtnCalculateState();
}
private void rdoSpeedFast_CheckedChanged(object sender, EventArgs e)
{
updateBtnCalculateState();
}
private void updateBtnCalculateState()
{
if (rdoMax.Checked)
{
m_times = -1;
}
if (rdoMax.Checked || rdoSpeedFast.Checked)
{
btnCalculate.Enabled = false;
m_duration = -1;
}
else
{
btnCalculate.Enabled = true;
}
}
private void btnStart_Click(object sender, EventArgs e)
{
try
{
if (chkSave.Checked)
{
if (m_filePath.Equals(""))
{
MessageBox.Show(PdnResources.GetString("Menu.file.Batchsaving.Pleasecsavepath.text"));
return;
}
if (!Directory.Exists(m_filePath))
{
Directory.CreateDirectory(m_filePath);//不存在就创建目录
}
}
if (Directory.Exists(m_fileTempPath))
{
DelectDir(m_fileTempPath);
}
else
{
Directory.CreateDirectory(m_fileTempPath);//不存在就创建目录
}
calculate();
m_filePath = txtSavePath.Text.Trim();
string prefix = txtPrefix.Text.Trim();
m_fileName = prefix;
Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
bool _isWorking = false;
///
/// 开始拍照
///
void Start()
{
_time = DateTime.Now;
_isWorking = true;
}
///
/// 停止拍照
///
void Stop()
{
_isWorking = false;
SaveAndOpen();
}
///
/// 停止按钮
///
///
///
private void btnStop_Click(object sender, EventArgs e)
{
Stop();
}
private void CameraTimedShooting_FormClosing(object sender, FormClosingEventArgs e)
{
CameraManager.FrameCallback -= CallbackDraw;
}
private void SaveAndOpen()
{
// 打包图片在主界面打开
string zipPath = ZipHandleHelper.CompressedZipPackage(m_fileTempPath);
if (!string.IsNullOrEmpty(zipPath))
{
this.Invoke(new Action(() =>
{
m_appWorkspace.OpenFileInNewWorkspace(zipPath);
}));
// 保存到硬盘
if (chkSave.Checked)
{
System.IO.File.Copy(zipPath, m_filePath + "\\" + txtPrefix.Text.Trim() + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".tga", true);
}
}
}
public static void DelectDir(string srcPath)
{
try
{
DirectoryInfo dir = new DirectoryInfo(srcPath);
FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
foreach (FileSystemInfo i in fileinfo)
{
if (i is DirectoryInfo) //判断是否文件夹
{
DirectoryInfo subdir = new DirectoryInfo(i.FullName);
subdir.Delete(true); //删除子目录和文件
}
else
{
System.IO.File.Delete(i.FullName); //删除指定文件
}
}
}
catch (Exception)
{
}
}
private void CameraTimedShooting_Load(object sender, EventArgs e)
{
CameraManager.FrameCallback += CallbackDraw;
}
DateTime _time;
private void CallbackDraw(Bitmap obj)
{
try
{
if (_isWorking)
{
var file = m_fileTempPath + "\\" + m_fileName + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";
//按时间
if (rdoSpeedFast.Checked && (rdoDuration.Checked || rdoMax.Checked))
{
if (m_duration < 0 || (DateTime.Now - _time).TotalSeconds < m_duration)
{
obj.Save(file, ImageFormat.Jpeg);
// m_savefiles.Add(file);
}
else
{
Stop();
}
}
else//次数
{
if ((DateTime.Now - _time).TotalMilliseconds >= m_timeLag || rdoSpeedFast.Checked)
{
m_times--;
_time = DateTime.Now;
obj.Save(file, ImageFormat.Jpeg);
//m_savefiles.Add(file);
if (m_times == 0)
Stop();
}
}
}
}
catch { }
}
private void timer1_Tick(object sender, EventArgs e)
{
btnStart.Enabled = !_isWorking;
btnStop.Enabled = _isWorking;
m_timeLag = (int)(cmbUnits.SelectedIndex == 0 ? nudTimeLapse.Value * 1000 : nudTimeLapse.Value);
}
}
}