CameraTimedShooting.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Drawing.Imaging;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using PaintDotNet.Base.CommTool;
  13. using PaintDotNet.SystemLayer;
  14. using TUCAMAPI;
  15. using TUCamera;
  16. namespace PaintDotNet.ImageCollect
  17. {
  18. internal class CameraTimedShooting : FloatingToolForm
  19. {
  20. #region
  21. /// <summary>
  22. /// Required designer variable.
  23. /// </summary>
  24. private System.ComponentModel.IContainer components = null;
  25. /// <summary>
  26. /// Clean up any resources being used.
  27. /// </summary>
  28. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  29. protected override void Dispose(bool disposing)
  30. {
  31. if (disposing && (components != null))
  32. {
  33. components.Dispose();
  34. }
  35. base.Dispose(disposing);
  36. }
  37. #region Windows Form Designer generated code
  38. private void InitializeLanguageText()
  39. {
  40. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  41. this.btnStop.Text = PdnResources.GetString("Menu.stop.text");
  42. this.btnStart.Text = PdnResources.GetString("Menu.Started.text");
  43. this.groupBox2.Text = PdnResources.GetString("Menu.imagecapture.timelapse.Timeintervalsetting.text");
  44. this.rdoTimeLapse.Text = PdnResources.GetString("Menu.timeinterval.text");
  45. this.rdoSpeedFast.Text = PdnResources.GetString("Menu.imagecapture.timelapse.Fastestspeed.text");
  46. this.groupBox3.Text = PdnResources.GetString("Menu.imagecapture.timelapse.Durationsetting.text");
  47. this.rdoDuration.Text = PdnResources.GetString("Menu.imagecapture.timelapse.duration.text");
  48. this.btnCalculate.Text = PdnResources.GetString("Menu.compute.text");
  49. this.rdoTimes.Text = "#" + PdnResources.GetString("Menu.imagecapture.timelapse.cycle.text");
  50. this.rdoMax.Text = PdnResources.GetString("Menu.imagecapture.timelapse.Maxduration.text");
  51. this.groupBox4.Text = PdnResources.GetString("Menu.imagecapture.timelapse.SaveSettings.text");
  52. this.btnModifyPath.Text = PdnResources.GetString("Menu.alter.text");
  53. this.label2.Text = PdnResources.GetString("Menu.Nameprefix.text") + ":";
  54. this.label1.Text = PdnResources.GetString("Menu.saveroute.text") + ":";
  55. this.chkSave.Text = PdnResources.GetString("Menu.imagecapture.timelapse.Savetoharddrive.text");
  56. this.Text = PdnResources.GetString("Menu.ImageCollection.TimedShooting.Text");
  57. }
  58. /// <summary>
  59. /// Required method for Designer support - do not modify
  60. /// the contents of this method with the code editor.
  61. /// </summary>
  62. private void InitializeComponent()
  63. {
  64. this.components = new System.ComponentModel.Container();
  65. this.groupBox1 = new System.Windows.Forms.GroupBox();
  66. this.btnStop = new System.Windows.Forms.Button();
  67. this.btnStart = new System.Windows.Forms.Button();
  68. this.groupBox2 = new System.Windows.Forms.GroupBox();
  69. this.cmbUnits = new System.Windows.Forms.ComboBox();
  70. this.nudTimeLapse = new System.Windows.Forms.NumericUpDown();
  71. this.rdoTimeLapse = new System.Windows.Forms.RadioButton();
  72. this.rdoSpeedFast = new System.Windows.Forms.RadioButton();
  73. this.groupBox3 = new System.Windows.Forms.GroupBox();
  74. this.cmbDuration = new System.Windows.Forms.ComboBox();
  75. this.nudDuration = new System.Windows.Forms.NumericUpDown();
  76. this.rdoDuration = new System.Windows.Forms.RadioButton();
  77. this.btnCalculate = new System.Windows.Forms.Button();
  78. this.nudTimes = new System.Windows.Forms.NumericUpDown();
  79. this.rdoTimes = new System.Windows.Forms.RadioButton();
  80. this.rdoMax = new System.Windows.Forms.RadioButton();
  81. this.groupBox4 = new System.Windows.Forms.GroupBox();
  82. this.btnModifyPath = new System.Windows.Forms.Button();
  83. this.txtPrefix = new System.Windows.Forms.TextBox();
  84. this.txtSavePath = new System.Windows.Forms.TextBox();
  85. this.label2 = new System.Windows.Forms.Label();
  86. this.label1 = new System.Windows.Forms.Label();
  87. this.chkSave = new System.Windows.Forms.CheckBox();
  88. this.timer1 = new System.Windows.Forms.Timer(this.components);
  89. this.groupBox1.SuspendLayout();
  90. this.groupBox2.SuspendLayout();
  91. ((System.ComponentModel.ISupportInitialize)(this.nudTimeLapse)).BeginInit();
  92. this.groupBox3.SuspendLayout();
  93. ((System.ComponentModel.ISupportInitialize)(this.nudDuration)).BeginInit();
  94. ((System.ComponentModel.ISupportInitialize)(this.nudTimes)).BeginInit();
  95. this.groupBox4.SuspendLayout();
  96. this.SuspendLayout();
  97. //
  98. // groupBox1
  99. //
  100. this.groupBox1.Controls.Add(this.btnStop);
  101. this.groupBox1.Controls.Add(this.btnStart);
  102. this.groupBox1.Location = new System.Drawing.Point(12, 12);
  103. this.groupBox1.Name = "groupBox1";
  104. this.groupBox1.Size = new System.Drawing.Size(348, 66);
  105. this.groupBox1.TabIndex = 0;
  106. this.groupBox1.TabStop = false;
  107. this.groupBox1.Text = "操作";
  108. //
  109. // btnStop
  110. //
  111. this.btnStop.Enabled = false;
  112. this.btnStop.Location = new System.Drawing.Point(258, 22);
  113. this.btnStop.Name = "btnStop";
  114. this.btnStop.Size = new System.Drawing.Size(68, 30);
  115. this.btnStop.TabIndex = 3;
  116. this.btnStop.Text = "停止";
  117. this.btnStop.UseVisualStyleBackColor = true;
  118. this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
  119. //
  120. // btnStart
  121. //
  122. this.btnStart.Location = new System.Drawing.Point(184, 22);
  123. this.btnStart.Name = "btnStart";
  124. this.btnStart.Size = new System.Drawing.Size(68, 30);
  125. this.btnStart.TabIndex = 2;
  126. this.btnStart.Text = "开始";
  127. this.btnStart.UseVisualStyleBackColor = true;
  128. this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
  129. //
  130. // groupBox2
  131. //
  132. this.groupBox2.Controls.Add(this.cmbUnits);
  133. this.groupBox2.Controls.Add(this.nudTimeLapse);
  134. this.groupBox2.Controls.Add(this.rdoTimeLapse);
  135. this.groupBox2.Controls.Add(this.rdoSpeedFast);
  136. this.groupBox2.Location = new System.Drawing.Point(12, 89);
  137. this.groupBox2.Name = "groupBox2";
  138. this.groupBox2.Size = new System.Drawing.Size(348, 100);
  139. this.groupBox2.TabIndex = 1;
  140. this.groupBox2.TabStop = false;
  141. this.groupBox2.Text = "时间间隔设置";
  142. //
  143. // cmbUnits
  144. //
  145. this.cmbUnits.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  146. this.cmbUnits.FormattingEnabled = true;
  147. this.cmbUnits.Location = new System.Drawing.Point(253, 61);
  148. this.cmbUnits.Name = "cmbUnits";
  149. this.cmbUnits.Size = new System.Drawing.Size(73, 20);
  150. this.cmbUnits.TabIndex = 3;
  151. //
  152. // nudTimeLapse
  153. //
  154. this.nudTimeLapse.Location = new System.Drawing.Point(147, 62);
  155. this.nudTimeLapse.Maximum = new decimal(new int[] {
  156. 1000,
  157. 0,
  158. 0,
  159. 0});
  160. this.nudTimeLapse.Minimum = new decimal(new int[] {
  161. 1,
  162. 0,
  163. 0,
  164. 0});
  165. this.nudTimeLapse.Name = "nudTimeLapse";
  166. this.nudTimeLapse.Size = new System.Drawing.Size(84, 21);
  167. this.nudTimeLapse.TabIndex = 2;
  168. this.nudTimeLapse.Value = new decimal(new int[] {
  169. 1,
  170. 0,
  171. 0,
  172. 0});
  173. //
  174. // rdoTimeLapse
  175. //
  176. this.rdoTimeLapse.AutoSize = true;
  177. this.rdoTimeLapse.Checked = true;
  178. this.rdoTimeLapse.Location = new System.Drawing.Point(16, 64);
  179. this.rdoTimeLapse.Name = "rdoTimeLapse";
  180. this.rdoTimeLapse.Size = new System.Drawing.Size(71, 16);
  181. this.rdoTimeLapse.TabIndex = 1;
  182. this.rdoTimeLapse.TabStop = true;
  183. this.rdoTimeLapse.Text = "时间间隔";
  184. this.rdoTimeLapse.UseVisualStyleBackColor = true;
  185. //
  186. // rdoSpeedFast
  187. //
  188. this.rdoSpeedFast.AutoSize = true;
  189. this.rdoSpeedFast.Location = new System.Drawing.Point(16, 34);
  190. this.rdoSpeedFast.Name = "rdoSpeedFast";
  191. this.rdoSpeedFast.Size = new System.Drawing.Size(71, 16);
  192. this.rdoSpeedFast.TabIndex = 0;
  193. this.rdoSpeedFast.Text = "最快速度";
  194. this.rdoSpeedFast.UseVisualStyleBackColor = true;
  195. this.rdoSpeedFast.CheckedChanged += new System.EventHandler(this.rdoSpeedFast_CheckedChanged);
  196. //
  197. // groupBox3
  198. //
  199. this.groupBox3.Controls.Add(this.cmbDuration);
  200. this.groupBox3.Controls.Add(this.nudDuration);
  201. this.groupBox3.Controls.Add(this.rdoDuration);
  202. this.groupBox3.Controls.Add(this.btnCalculate);
  203. this.groupBox3.Controls.Add(this.nudTimes);
  204. this.groupBox3.Controls.Add(this.rdoTimes);
  205. this.groupBox3.Controls.Add(this.rdoMax);
  206. this.groupBox3.Location = new System.Drawing.Point(12, 205);
  207. this.groupBox3.Name = "groupBox3";
  208. this.groupBox3.Size = new System.Drawing.Size(348, 148);
  209. this.groupBox3.TabIndex = 2;
  210. this.groupBox3.TabStop = false;
  211. this.groupBox3.Text = "持续时间设置";
  212. //
  213. // cmbDuration
  214. //
  215. this.cmbDuration.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  216. this.cmbDuration.FormattingEnabled = true;
  217. this.cmbDuration.Location = new System.Drawing.Point(253, 106);
  218. this.cmbDuration.Name = "cmbDuration";
  219. this.cmbDuration.Size = new System.Drawing.Size(73, 20);
  220. this.cmbDuration.TabIndex = 7;
  221. //
  222. // nudDuration
  223. //
  224. this.nudDuration.DecimalPlaces = 2;
  225. this.nudDuration.Increment = new decimal(new int[] {
  226. 1,
  227. 0,
  228. 0,
  229. 131072});
  230. this.nudDuration.Location = new System.Drawing.Point(147, 107);
  231. this.nudDuration.Maximum = new decimal(new int[] {
  232. 10000,
  233. 0,
  234. 0,
  235. 0});
  236. this.nudDuration.Minimum = new decimal(new int[] {
  237. 1,
  238. 0,
  239. 0,
  240. 131072});
  241. this.nudDuration.Name = "nudDuration";
  242. this.nudDuration.Size = new System.Drawing.Size(84, 21);
  243. this.nudDuration.TabIndex = 6;
  244. this.nudDuration.Value = new decimal(new int[] {
  245. 1,
  246. 0,
  247. 0,
  248. 131072});
  249. //
  250. // rdoDuration
  251. //
  252. this.rdoDuration.AutoSize = true;
  253. this.rdoDuration.Location = new System.Drawing.Point(16, 106);
  254. this.rdoDuration.Name = "rdoDuration";
  255. this.rdoDuration.Size = new System.Drawing.Size(71, 16);
  256. this.rdoDuration.TabIndex = 5;
  257. this.rdoDuration.Text = "持续时间";
  258. this.rdoDuration.UseVisualStyleBackColor = true;
  259. //
  260. // btnCalculate
  261. //
  262. this.btnCalculate.Location = new System.Drawing.Point(253, 60);
  263. this.btnCalculate.Name = "btnCalculate";
  264. this.btnCalculate.Size = new System.Drawing.Size(73, 27);
  265. this.btnCalculate.TabIndex = 4;
  266. this.btnCalculate.Text = "计算";
  267. this.btnCalculate.UseVisualStyleBackColor = true;
  268. this.btnCalculate.Click += new System.EventHandler(this.btnCalculate_Click);
  269. //
  270. // nudTimes
  271. //
  272. this.nudTimes.Location = new System.Drawing.Point(147, 62);
  273. this.nudTimes.Maximum = new decimal(new int[] {
  274. 10000,
  275. 0,
  276. 0,
  277. 0});
  278. this.nudTimes.Minimum = new decimal(new int[] {
  279. 1,
  280. 0,
  281. 0,
  282. 0});
  283. this.nudTimes.Name = "nudTimes";
  284. this.nudTimes.Size = new System.Drawing.Size(84, 21);
  285. this.nudTimes.TabIndex = 3;
  286. this.nudTimes.Value = new decimal(new int[] {
  287. 1,
  288. 0,
  289. 0,
  290. 0});
  291. //
  292. // rdoTimes
  293. //
  294. this.rdoTimes.AutoSize = true;
  295. this.rdoTimes.Checked = true;
  296. this.rdoTimes.Location = new System.Drawing.Point(16, 68);
  297. this.rdoTimes.Name = "rdoTimes";
  298. this.rdoTimes.Size = new System.Drawing.Size(53, 16);
  299. this.rdoTimes.TabIndex = 2;
  300. this.rdoTimes.TabStop = true;
  301. this.rdoTimes.Text = "#循环";
  302. this.rdoTimes.UseVisualStyleBackColor = true;
  303. //
  304. // rdoMax
  305. //
  306. this.rdoMax.AutoSize = true;
  307. this.rdoMax.Location = new System.Drawing.Point(16, 34);
  308. this.rdoMax.Name = "rdoMax";
  309. this.rdoMax.Size = new System.Drawing.Size(95, 16);
  310. this.rdoMax.TabIndex = 1;
  311. this.rdoMax.Text = "最大持续时间";
  312. this.rdoMax.UseVisualStyleBackColor = true;
  313. this.rdoMax.CheckedChanged += new System.EventHandler(this.rdoMax_CheckedChanged);
  314. //
  315. // groupBox4
  316. //
  317. this.groupBox4.Controls.Add(this.btnModifyPath);
  318. this.groupBox4.Controls.Add(this.txtPrefix);
  319. this.groupBox4.Controls.Add(this.txtSavePath);
  320. this.groupBox4.Controls.Add(this.label2);
  321. this.groupBox4.Controls.Add(this.label1);
  322. this.groupBox4.Controls.Add(this.chkSave);
  323. this.groupBox4.Location = new System.Drawing.Point(12, 368);
  324. this.groupBox4.Name = "groupBox4";
  325. this.groupBox4.Size = new System.Drawing.Size(348, 138);
  326. this.groupBox4.TabIndex = 3;
  327. this.groupBox4.TabStop = false;
  328. this.groupBox4.Text = "保存设置";
  329. //
  330. // btnModifyPath
  331. //
  332. this.btnModifyPath.Location = new System.Drawing.Point(253, 69);
  333. this.btnModifyPath.Name = "btnModifyPath";
  334. this.btnModifyPath.Size = new System.Drawing.Size(73, 25);
  335. this.btnModifyPath.TabIndex = 5;
  336. this.btnModifyPath.Text = "更改";
  337. this.btnModifyPath.UseVisualStyleBackColor = true;
  338. this.btnModifyPath.Click += new System.EventHandler(this.btnModifyPath_Click);
  339. //
  340. // txtPrefix
  341. //
  342. this.txtPrefix.Location = new System.Drawing.Point(101, 100);
  343. this.txtPrefix.Name = "txtPrefix";
  344. this.txtPrefix.Size = new System.Drawing.Size(141, 21);
  345. this.txtPrefix.TabIndex = 4;
  346. //
  347. // txtSavePath
  348. //
  349. this.txtSavePath.Location = new System.Drawing.Point(101, 69);
  350. this.txtSavePath.Name = "txtSavePath";
  351. this.txtSavePath.ReadOnly = true;
  352. this.txtSavePath.Size = new System.Drawing.Size(141, 21);
  353. this.txtSavePath.TabIndex = 3;
  354. //
  355. // label2
  356. //
  357. this.label2.AutoSize = true;
  358. this.label2.Location = new System.Drawing.Point(13, 106);
  359. this.label2.Name = "label2";
  360. this.label2.Size = new System.Drawing.Size(65, 12);
  361. this.label2.TabIndex = 2;
  362. this.label2.Text = "名称前缀:";
  363. //
  364. // label1
  365. //
  366. this.label1.AutoSize = true;
  367. this.label1.Location = new System.Drawing.Point(13, 72);
  368. this.label1.Name = "label1";
  369. this.label1.Size = new System.Drawing.Size(65, 12);
  370. this.label1.TabIndex = 1;
  371. this.label1.Text = "保存路径:";
  372. //
  373. // chkSave
  374. //
  375. this.chkSave.AutoSize = true;
  376. this.chkSave.Checked = true;
  377. this.chkSave.CheckState = System.Windows.Forms.CheckState.Checked;
  378. this.chkSave.Location = new System.Drawing.Point(16, 34);
  379. this.chkSave.Name = "chkSave";
  380. this.chkSave.Size = new System.Drawing.Size(84, 16);
  381. this.chkSave.TabIndex = 0;
  382. this.chkSave.Text = "保存到硬盘";
  383. this.chkSave.UseVisualStyleBackColor = true;
  384. //
  385. // timer1
  386. //
  387. this.timer1.Enabled = true;
  388. this.timer1.Interval = 50;
  389. this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
  390. //
  391. // CameraTimedShooting
  392. //
  393. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  394. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  395. this.ClientSize = new System.Drawing.Size(378, 518);
  396. this.Controls.Add(this.groupBox4);
  397. this.Controls.Add(this.groupBox3);
  398. this.Controls.Add(this.groupBox2);
  399. this.Controls.Add(this.groupBox1);
  400. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  401. this.Name = "CameraTimedShooting";
  402. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  403. this.Text = "定时拍摄";
  404. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.CameraTimedShooting_FormClosing);
  405. this.Load += new System.EventHandler(this.CameraTimedShooting_Load);
  406. this.Controls.SetChildIndex(this.groupBox1, 0);
  407. this.Controls.SetChildIndex(this.groupBox2, 0);
  408. this.Controls.SetChildIndex(this.groupBox3, 0);
  409. this.Controls.SetChildIndex(this.groupBox4, 0);
  410. this.groupBox1.ResumeLayout(false);
  411. this.groupBox2.ResumeLayout(false);
  412. this.groupBox2.PerformLayout();
  413. ((System.ComponentModel.ISupportInitialize)(this.nudTimeLapse)).EndInit();
  414. this.groupBox3.ResumeLayout(false);
  415. this.groupBox3.PerformLayout();
  416. ((System.ComponentModel.ISupportInitialize)(this.nudDuration)).EndInit();
  417. ((System.ComponentModel.ISupportInitialize)(this.nudTimes)).EndInit();
  418. this.groupBox4.ResumeLayout(false);
  419. this.groupBox4.PerformLayout();
  420. this.ResumeLayout(false);
  421. }
  422. #endregion
  423. private System.Windows.Forms.GroupBox groupBox1;
  424. private System.Windows.Forms.Button btnStop;
  425. private System.Windows.Forms.Button btnStart;
  426. private System.Windows.Forms.GroupBox groupBox2;
  427. private System.Windows.Forms.ComboBox cmbUnits;
  428. private System.Windows.Forms.NumericUpDown nudTimeLapse;
  429. private System.Windows.Forms.RadioButton rdoTimeLapse;
  430. private System.Windows.Forms.RadioButton rdoSpeedFast;
  431. private System.Windows.Forms.GroupBox groupBox3;
  432. private System.Windows.Forms.ComboBox cmbDuration;
  433. private System.Windows.Forms.NumericUpDown nudDuration;
  434. private System.Windows.Forms.RadioButton rdoDuration;
  435. private System.Windows.Forms.Button btnCalculate;
  436. private System.Windows.Forms.NumericUpDown nudTimes;
  437. private System.Windows.Forms.RadioButton rdoTimes;
  438. private System.Windows.Forms.RadioButton rdoMax;
  439. private System.Windows.Forms.GroupBox groupBox4;
  440. private System.Windows.Forms.Button btnModifyPath;
  441. private System.Windows.Forms.TextBox txtPrefix;
  442. private System.Windows.Forms.TextBox txtSavePath;
  443. private System.Windows.Forms.Label label2;
  444. private System.Windows.Forms.Label label1;
  445. private System.Windows.Forms.CheckBox chkSave;
  446. #endregion
  447. /// <summary>
  448. /// 时间间隔单位
  449. /// </summary>
  450. private string[] m_timeUnitsArray = new string[] { PdnResources.GetString("Menu.second.text"), PdnResources.GetString("Menu.millisecond.text") };
  451. private string m_filePath = "";
  452. private string m_fileTempPath = Application.StartupPath + "\\TimedShootTemp";
  453. private string m_fileName;
  454. /// <summary>
  455. /// 时间间隔 (毫秒)
  456. /// </summary>
  457. private int m_timeLag;
  458. // 循环次数
  459. private int m_times = 0;
  460. // 持续时间 (毫秒)
  461. private int m_duration = 0;
  462. private TUCamera.TUCamera m_camera;
  463. private Timer timer1;
  464. private AppWorkspace m_appWorkspace;
  465. public CameraTimedShooting(AppWorkspace workspace)
  466. {
  467. m_appWorkspace = workspace;
  468. InitializeComponent();
  469. InitializeLanguageText();
  470. InitializeControlData();
  471. this.Load += (s, e) =>
  472. {
  473. m_filePath = Settings.CurrentUser.GetString("CameraTimedShootingPath", "");
  474. txtSavePath.Text = m_filePath;
  475. txtPrefix.Text = Settings.CurrentUser.GetString("CameraTimedShootingPrefix", "");
  476. };
  477. this.FormClosing += (s, e) =>
  478. {
  479. Settings.CurrentUser.SetString("CameraTimedShootingPath", txtSavePath.Text);
  480. Settings.CurrentUser.SetString("CameraTimedShootingPrefix", txtPrefix.Text);
  481. };
  482. }
  483. /// <summary>
  484. /// 设置下拉等数据源
  485. /// </summary>
  486. private void InitializeControlData()
  487. {
  488. this.cmbUnits.Items.Add(m_timeUnitsArray[0]);
  489. this.cmbUnits.SelectedIndex = 0;
  490. this.cmbDuration.Items.Add(m_timeUnitsArray[0]);
  491. this.cmbDuration.SelectedIndex = 0;
  492. this.txtSavePath.Text = m_filePath;
  493. m_camera = TUCameraManager.GetInstance().GetCurrentCamera();
  494. }
  495. private void btnModifyPath_Click(object sender, EventArgs e)
  496. {
  497. FolderBrowserDialog folderBroeser = new FolderBrowserDialog();
  498. if (folderBroeser.ShowDialog() == DialogResult.OK)
  499. {
  500. m_filePath = folderBroeser.SelectedPath;
  501. txtSavePath.Text = m_filePath;
  502. }
  503. }
  504. private void btnCalculate_Click(object sender, EventArgs e)
  505. {
  506. calculate();
  507. }
  508. private void calculate()
  509. {
  510. if (rdoTimes.Checked)
  511. {
  512. m_times = Convert.ToInt32(nudTimes.Value);
  513. m_duration = m_timeLag * m_times;
  514. if (m_duration >= 1000)
  515. {
  516. nudDuration.Value = m_duration / 1000;
  517. this.cmbDuration.SelectedIndex = 0;
  518. }
  519. else
  520. {
  521. nudDuration.Value = m_duration;
  522. this.cmbDuration.SelectedIndex = 1;
  523. }
  524. }
  525. else if (rdoDuration.Checked)
  526. {
  527. int tmpLapse = 1;
  528. if (cmbDuration.SelectedItem.Equals(PdnResources.GetString("Menu.second.text")))
  529. {
  530. tmpLapse = 1000;
  531. }
  532. m_duration = (int)(nudDuration.Value * tmpLapse);
  533. m_times = m_duration / m_timeLag;
  534. if (m_times <= 0)
  535. {
  536. m_times = 1;
  537. }
  538. nudTimes.Value = m_times;
  539. }
  540. }
  541. private void rdoMax_CheckedChanged(object sender, EventArgs e)
  542. {
  543. updateBtnCalculateState();
  544. }
  545. private void rdoSpeedFast_CheckedChanged(object sender, EventArgs e)
  546. {
  547. updateBtnCalculateState();
  548. }
  549. private void updateBtnCalculateState()
  550. {
  551. if (rdoMax.Checked)
  552. {
  553. m_times = -1;
  554. }
  555. if (rdoMax.Checked || rdoSpeedFast.Checked)
  556. {
  557. btnCalculate.Enabled = false;
  558. m_duration = -1;
  559. }
  560. else
  561. {
  562. btnCalculate.Enabled = true;
  563. }
  564. }
  565. private void btnStart_Click(object sender, EventArgs e)
  566. {
  567. try
  568. {
  569. if (chkSave.Checked)
  570. {
  571. if (m_filePath.Equals(""))
  572. {
  573. MessageBox.Show(PdnResources.GetString("Menu.file.Batchsaving.Pleasecsavepath.text"));
  574. return;
  575. }
  576. if (!Directory.Exists(m_filePath))
  577. {
  578. Directory.CreateDirectory(m_filePath);//不存在就创建目录
  579. }
  580. }
  581. if (Directory.Exists(m_fileTempPath))
  582. {
  583. DelectDir(m_fileTempPath);
  584. }
  585. else
  586. {
  587. Directory.CreateDirectory(m_fileTempPath);//不存在就创建目录
  588. }
  589. calculate();
  590. m_filePath = txtSavePath.Text.Trim();
  591. string prefix = txtPrefix.Text.Trim();
  592. m_fileName = prefix;
  593. Start();
  594. }
  595. catch (Exception ex)
  596. {
  597. MessageBox.Show(ex.Message);
  598. }
  599. }
  600. bool _isWorking = false;
  601. /// <summary>
  602. /// 开始拍照
  603. /// </summary>
  604. void Start()
  605. {
  606. _time = DateTime.Now;
  607. _isWorking = true;
  608. }
  609. /// <summary>
  610. /// 停止拍照
  611. /// </summary>
  612. void Stop()
  613. {
  614. _isWorking = false;
  615. SaveAndOpen();
  616. }
  617. /// <summary>
  618. /// 停止按钮
  619. /// </summary>
  620. /// <param name="sender"></param>
  621. /// <param name="e"></param>
  622. private void btnStop_Click(object sender, EventArgs e)
  623. {
  624. Stop();
  625. }
  626. private void CameraTimedShooting_FormClosing(object sender, FormClosingEventArgs e)
  627. {
  628. m_camera.m_bufHandler -= CallbackDraw;
  629. m_camera.StopWaitForFrame();
  630. }
  631. private void SaveAndOpen()
  632. {
  633. // 打包图片在主界面打开
  634. string zipPath = ZipHandleHelper.CompressedZipPackage(m_fileTempPath);
  635. if (!string.IsNullOrEmpty(zipPath))
  636. {
  637. this.Invoke(new Action(() =>
  638. {
  639. m_appWorkspace.OpenFileInNewWorkspace(zipPath);
  640. }));
  641. // 保存到硬盘
  642. if (chkSave.Checked)
  643. {
  644. System.IO.File.Copy(zipPath, m_filePath + "\\" + txtPrefix.Text.Trim() + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".tga", true);
  645. }
  646. }
  647. }
  648. public static void DelectDir(string srcPath)
  649. {
  650. try
  651. {
  652. DirectoryInfo dir = new DirectoryInfo(srcPath);
  653. FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
  654. foreach (FileSystemInfo i in fileinfo)
  655. {
  656. if (i is DirectoryInfo) //判断是否文件夹
  657. {
  658. DirectoryInfo subdir = new DirectoryInfo(i.FullName);
  659. subdir.Delete(true); //删除子目录和文件
  660. }
  661. else
  662. {
  663. System.IO.File.Delete(i.FullName); //删除指定文件
  664. }
  665. }
  666. }
  667. catch (Exception)
  668. {
  669. }
  670. }
  671. private void CameraTimedShooting_Load(object sender, EventArgs e)
  672. {
  673. m_camera.StartWaitForFrame();
  674. m_camera.m_bufHandler += CallbackDraw;
  675. }
  676. DateTime _time;
  677. private void CallbackDraw(Bitmap obj)
  678. {
  679. try
  680. {
  681. if (_isWorking)
  682. {
  683. var file = m_fileTempPath + "\\" + m_fileName + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";
  684. //按时间
  685. if (rdoSpeedFast.Checked && (rdoDuration.Checked || rdoMax.Checked))
  686. {
  687. if (m_duration < 0 || (DateTime.Now - _time).TotalSeconds < m_duration)
  688. {
  689. obj.Save(file, ImageFormat.Jpeg);
  690. // m_savefiles.Add(file);
  691. }
  692. else
  693. {
  694. Stop();
  695. }
  696. }
  697. else//次数
  698. {
  699. if ((DateTime.Now - _time).TotalMilliseconds >= m_timeLag || rdoSpeedFast.Checked)
  700. {
  701. m_times--;
  702. _time = DateTime.Now;
  703. obj.Save(file, ImageFormat.Jpeg);
  704. //m_savefiles.Add(file);
  705. if (m_times == 0)
  706. Stop();
  707. }
  708. }
  709. }
  710. }
  711. catch { }
  712. }
  713. private void timer1_Tick(object sender, EventArgs e)
  714. {
  715. btnStart.Enabled = !_isWorking;
  716. btnStop.Enabled = _isWorking;
  717. m_timeLag = (int)(cmbUnits.SelectedIndex == 0 ? nudTimeLapse.Value * 1000 : nudTimeLapse.Value);
  718. }
  719. }
  720. }