123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759 |
- 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
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- 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");
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- 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
- /// <summary>
- /// 时间间隔单位
- /// </summary>
- 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;
- /// <summary>
- /// 时间间隔 (毫秒)
- /// </summary>
- 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);
- };
- }
- /// <summary>
- /// 设置下拉等数据源
- /// </summary>
- 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;
- /// <summary>
- /// 开始拍照
- /// </summary>
- void Start()
- {
- _time = DateTime.Now;
- _isWorking = true;
- }
- /// <summary>
- /// 停止拍照
- /// </summary>
- void Stop()
- {
- _isWorking = false;
- SaveAndOpen();
- }
- /// <summary>
- /// 停止按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- }
|