PlotTheMeasurementRange.cs 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536
  1. using OpenCvSharp;
  2. using Resources;
  3. using SmartCoalApplication.Annotation;
  4. using SmartCoalApplication.Annotation.FieldView;
  5. using SmartCoalApplication.Base.CommTool;
  6. using SmartCoalApplication.Base.FunctionModel;
  7. using SmartCoalApplication.Core;
  8. using SmartCoalApplication.Core.CustomControl;
  9. using SmartCoalApplication.Core.Param;
  10. using SmartCoalApplication.ParameterSet;
  11. using SmartCoalApplication.Resources;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.ComponentModel;
  15. using System.Data;
  16. using System.Drawing;
  17. using System.Drawing.Drawing2D;
  18. using System.Drawing.Imaging;
  19. using System.IO;
  20. using System.Linq;
  21. using System.Reflection;
  22. using System.Text;
  23. using System.Threading.Tasks;
  24. using System.Windows.Forms;
  25. using static SmartCoalApplication.AutomaticMeasurement.ImageTools;
  26. namespace SmartCoalApplication.AutomaticMeasurement
  27. {
  28. internal partial class PlotTheMeasurementRange : PdnBaseForm
  29. {
  30. /// <summary>
  31. /// 分析设置存储信息
  32. /// </summary>
  33. protected AnalyzeSettingModel analyzeSettingModel = new AnalyzeSettingModel();
  34. /// <summary>
  35. /// 图片名称对应关系
  36. /// </summary>
  37. Dictionary<string, string> pNames = new Dictionary<string, string>();
  38. private List<Bitmap> pictures = new List<Bitmap>();
  39. private List<Bitmap> originalPictures = new List<Bitmap>();
  40. private List<Bitmap> oldOriginalPictures = new List<Bitmap>();
  41. private List<string> pictureNames = new List<string>();
  42. private int index = new int();
  43. private AppWorkspace appWorkspace;
  44. private CommonControlButtons commonControlButtons;
  45. private Bitmap bitmap;
  46. /// <summary>
  47. /// hint 提示信息
  48. /// </summary>
  49. public ToolTip toolTip;
  50. /// <summary>
  51. /// 图像面板
  52. /// </summary>
  53. private DocumentWorkspaceWindow documentWorkspace;
  54. /// <summary>
  55. /// 图像面板
  56. /// </summary>
  57. private AutomaticMeasurement AutomaticMeasurement;
  58. private Dictionary<int, GraphicsList> dataList = new Dictionary<int, GraphicsList>();
  59. private int thisindex;
  60. private int selectedIndex = -1;
  61. private Dictionary<int, List<GraphicsList>> GraphicsList = new Dictionary<int, List<GraphicsList>>();
  62. /// <summary>
  63. /// 播放模式 1 从后播放 2 从前往后播
  64. /// </summary>
  65. private int playType = 2;
  66. /// <summary>
  67. /// 播放模式 是否循环播放
  68. /// </summary>
  69. private bool isLoop = false;
  70. /// <summary>
  71. /// 播放还是暂停
  72. /// </summary>
  73. private bool isPlay = false;
  74. public List<Bitmap> BitmapArray = new List<Bitmap>();
  75. public int OverlapWidth { get; set; }
  76. public int OverlapHeight { get; set; }
  77. private bool isNormal = false;
  78. private AutomaticMeasurementModel automaticMeasurement;
  79. private bool startSpin = false;
  80. private System.Drawing.PointF startPoint;
  81. private System.Drawing.PointF endPoint;
  82. bool isErzhiCheckBox = false;
  83. Dictionary<int, List<bool>> isErzhichuliList = new Dictionary<int, List<bool>>();
  84. private Dictionary<int, bool> dataIsErzhichuliList = new Dictionary<int, bool>();
  85. bool isFanweiCheckBox = false;
  86. Dictionary<int, List<bool>> isFanweibuchangList = new Dictionary<int, List<bool>>();
  87. private Dictionary<int, bool> dataIsFanweibuchangList = new Dictionary<int, bool>();
  88. Dictionary<int, List<bool>> boolList = new Dictionary<int, List<bool>>();
  89. private Dictionary<int, bool> dataBoolList = new Dictionary<int, bool>();
  90. private double hasAngle = 0;
  91. public PlotTheMeasurementRange(List<Bitmap> pictures, List<string> pictureNames, AppWorkspace appWorkspace, AutomaticMeasurement form, int index, Dictionary<int, List<GraphicsList>> GraphicsList, Dictionary<int, List<bool>> boolList,bool showCheckBox
  92. , Dictionary<int, List<bool>> isFanweibuchangList, bool isFanweibuchangCheckBox, Dictionary<int, List<bool>> isErzhichuliList, bool isErzhichuliCheckBox)
  93. {
  94. this.pictures = pictures;
  95. this.originalPictures.AddRange(pictures);
  96. this.oldOriginalPictures.AddRange(pictures);
  97. this.pictureNames = pictureNames;
  98. InitializeComponent();
  99. InitializeComponent2();
  100. #region [播放按钮初始化]
  101. //
  102. // 从后往前播放
  103. //
  104. this.button1.Image = PdnResources.GetImageResource("Icons.MultiFromAfterPlayIcon.png").Reference;
  105. this.button1.FlatStyle = FlatStyle.Flat;
  106. this.button1.FlatAppearance.BorderSize = 0;
  107. //
  108. // 从前往后播放
  109. //
  110. this.button2.Image = PdnResources.GetImageResource("Icons.MultiFromBehindPlayIcon.png").Reference;
  111. this.button2.FlatStyle = FlatStyle.Flat;
  112. this.button2.FlatAppearance.BorderSize = 0;
  113. this.button2.BackColor = Color.DarkGray;
  114. //
  115. // 循环播放
  116. //
  117. this.button3.Image = PdnResources.GetImageResource("Icons.MultiCirclePlayIcon.png").Reference;
  118. this.button3.FlatStyle = FlatStyle.Flat;
  119. this.button3.FlatAppearance.BorderSize = 0;
  120. //
  121. // 播放(暂停) 备注:这里需要判断显示播放/暂停
  122. //
  123. this.button4.Image = PdnResources.GetImageResource("Icons.MultiNowPlayIcon.png").Reference;
  124. this.button4.FlatStyle = FlatStyle.Flat;
  125. this.button4.FlatAppearance.BorderSize = 0;
  126. this.toolTip = new ToolTip();
  127. this.toolTip.SetToolTip(this.button1, PdnResources.GetString("Menu.Playitbackwards.text"));
  128. this.toolTip.SetToolTip(this.button2, PdnResources.GetString("Menu.Playbackandforth.text"));
  129. this.toolTip.SetToolTip(this.button3, PdnResources.GetString("Menu.Loopfor.text"));
  130. this.toolTip.SetToolTip(this.button4, PdnResources.GetString("Menu.Playpause.text"));
  131. #endregion
  132. this.Icon = PdnInfo.AppIcon;
  133. this.appWorkspace = appWorkspace;
  134. this.AutomaticMeasurement = form;
  135. thisindex = index;
  136. this.GraphicsList = GraphicsList;
  137. this.dataList = new Dictionary<int, GraphicsList>();
  138. if (this.GraphicsList.ContainsKey(thisindex))
  139. {
  140. int dataIndex = 0;
  141. foreach (var item in this.GraphicsList[thisindex])
  142. {
  143. dataList.Add(dataIndex, item);
  144. dataIndex++;
  145. }
  146. }
  147. this.boolList = boolList;
  148. if (this.boolList.ContainsKey(thisindex))
  149. {
  150. int dataIndex = 0;
  151. foreach (var item in this.boolList[thisindex])
  152. {
  153. dataBoolList.Add(dataIndex, item);
  154. dataIndex++;
  155. }
  156. }
  157. this.isFanweibuchangList = isFanweibuchangList;
  158. if (this.isFanweibuchangList.ContainsKey(thisindex))
  159. {
  160. int dataIndex = 0;
  161. foreach (var item in this.isFanweibuchangList[thisindex])
  162. {
  163. dataIsFanweibuchangList.Add(dataIndex, item);
  164. dataIndex++;
  165. }
  166. }
  167. this.isErzhichuliList = isErzhichuliList;
  168. if (this.isErzhichuliList.ContainsKey(thisindex))
  169. {
  170. int dataIndex = 0;
  171. foreach (var item in this.isErzhichuliList[thisindex])
  172. {
  173. dataIsErzhichuliList.Add(dataIndex, item);
  174. dataIndex++;
  175. }
  176. }
  177. #region [图像面板相关]
  178. //
  179. //初始化图像控件
  180. //
  181. this.documentWorkspace = new DocumentWorkspaceWindow(this.appWorkspace);
  182. this.documentWorkspace.Cursor = Cursors.Default;
  183. this.documentWorkspace.Dock = DockStyle.Fill;
  184. this.documentWorkspace.HookMouseEvents();
  185. this.documentWorkspace.Visible = true;
  186. //this.documentWorkspace.panel.Click += new EventHandler(this.documentWorkspace_panel_Click);
  187. this.documentWorkspace.panel.MouseDown += new MouseEventHandler(this.documentWorkspace_panel_MouseDown);
  188. this.documentWorkspace.panel.MouseMove += new MouseEventHandler(this.documentWorkspace_panel_MouseMove);
  189. this.documentWorkspace.panel.MouseUp += new MouseEventHandler(this.documentWorkspace_panel_MouseUp);
  190. PdnBaseForm.RegisterFormHotKey(Keys.Delete, OnDeleteHotKeyPressed);
  191. PdnBaseForm.RegisterFormHotKey(Keys.Control | Keys.Delete, OneDataOnDeleteHotKeyPressed);
  192. this.documentWorkspace.keepDraw = false;
  193. PdnBaseForm.RegisterFormHotKey(Keys.Left, lastPicture);
  194. PdnBaseForm.RegisterFormHotKey(Keys.Up, lastPicture);
  195. PdnBaseForm.RegisterFormHotKey(Keys.Down, nextPicture);
  196. PdnBaseForm.RegisterFormHotKey(Keys.Right, nextPicture);
  197. this.groupBoxZhangshu.Controls.Add(this.documentWorkspace);
  198. #endregion
  199. this.commonControlButtons = new CommonControlButtons();
  200. this.commonControlButtons.Dock = DockStyle.Top;
  201. this.commonControlButtons.Height = 30;
  202. this.commonControlButtons.HideZoomToWindowAndActualSize();
  203. if (showCheckBox)
  204. {
  205. this.commonControlButtons.ShowCheckBox();
  206. if (dataBoolList.Count > 0)
  207. {
  208. this.commonControlButtons.isModeCheckBox.Checked = dataBoolList[0];
  209. }
  210. }
  211. else if (isFanweibuchangCheckBox)
  212. {
  213. isFanweiCheckBox = isFanweibuchangCheckBox;
  214. this.commonControlButtons.ShowIsFanweibuchang();
  215. if (dataIsFanweibuchangList.Count > 0)
  216. {
  217. this.commonControlButtons.isModeCheckBox.Checked = dataIsFanweibuchangList[0];
  218. }
  219. }
  220. else if (isErzhichuliCheckBox)
  221. {
  222. isErzhiCheckBox = isErzhichuliCheckBox;
  223. this.commonControlButtons.ShowIsErzhichuli();
  224. if (dataIsErzhichuliList.Count > 0)
  225. {
  226. this.commonControlButtons.isModeCheckBox.Checked = dataIsErzhichuliList[0];
  227. }
  228. }
  229. this.groupBoxZhangshu.Controls.Add(commonControlButtons);
  230. InitCommonButtonEvent();
  231. this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.ViewRectangle;
  232. //this.documentWorkspace.SetContinuousDrawingVoid(true);
  233. this.PlotTheMeasurementRange_Load();
  234. #region [播放事件初始化]
  235. this.triangleTrackBar1.Value = 1;
  236. this.triangleTrackBar1.Maximum = this.listPictureName.Items.Count;
  237. this.textBox1.Text = $"{this.listPictureName.SelectedIndex + 1}/{this.triangleTrackBar1.Maximum}";
  238. #endregion
  239. #region [默认叠加]
  240. this.button6_Click(null, null);
  241. #endregion
  242. this.getLastData();
  243. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.saveLastData);
  244. }
  245. private void InitializeComponent2()
  246. {
  247. this.Text = PdnResources.GetString("NewDrawMeasurementRange");
  248. this.groupBox1.Text = PdnResources.GetString("NewOperation");
  249. this.checkBox1.Text = PdnResources.GetString("NewPauseDrawing");
  250. this.buttonOKDraw.Text = PdnResources.GetString("NewMakeSureDraw");
  251. this.groupBox2.Text = PdnResources.GetString("NewPictureList");
  252. this.button6.Text = PdnResources.GetString("NewSuperposition");
  253. this.button5.Text = PdnResources.GetString("NewNormal");
  254. this.label1.Text = PdnResources.GetString("NewTransparency") +":";
  255. this.groupBoxZhangshu.Text = PdnResources.GetString("NewTheFirstNne");
  256. }
  257. #region [参数保存]
  258. /// <summary>
  259. /// 获取上次操作参数
  260. /// </summary>
  261. private void getLastData()
  262. {
  263. string filePath = Application.StartupPath + "\\Config\\Default\\ParameterSaving\\AutomaticMeasurement.xml";
  264. if (!System.IO.File.Exists(filePath))
  265. {
  266. automaticMeasurement = new AutomaticMeasurementModel();
  267. automaticMeasurement.PlotTheMeasurementRangeModels = new PlotTheMeasurementRangeModel();
  268. string porosityInfoXml = XmlSerializeHelper.XmlSerialize<AutomaticMeasurementModel>(automaticMeasurement);
  269. Directory.CreateDirectory(Application.StartupPath + "\\Config\\Default\\ParameterSaving\\");
  270. FileOperationHelper.WriteStringToFile(porosityInfoXml, filePath, FileMode.CreateNew);
  271. }
  272. else
  273. {
  274. automaticMeasurement = XmlSerializeHelper.DESerializer<AutomaticMeasurementModel>(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open));
  275. if (automaticMeasurement.PlotTheMeasurementRangeModels == null)
  276. {
  277. automaticMeasurement.PlotTheMeasurementRangeModels = new PlotTheMeasurementRangeModel();
  278. }
  279. if (automaticMeasurement.PlotTheMeasurementRangeModels.hasUsed)
  280. {
  281. checkBox1.Checked = automaticMeasurement.PlotTheMeasurementRangeModels.parameter1;
  282. textBox2.Text = automaticMeasurement.PlotTheMeasurementRangeModels.parameter2.ToString();
  283. this.timer1.Interval = automaticMeasurement.PlotTheMeasurementRangeModels.parameter2;
  284. }
  285. }
  286. }
  287. /// <summary>
  288. /// 保存上次操作参数
  289. /// </summary>
  290. private void saveLastData(object sender, EventArgs e)
  291. {
  292. if (automaticMeasurement.PlotTheMeasurementRangeModels == null)
  293. {
  294. automaticMeasurement.PlotTheMeasurementRangeModels = new PlotTheMeasurementRangeModel();
  295. }
  296. int Interval = 1000;
  297. try
  298. {
  299. Interval = Convert.ToInt32(textBox2.Text);
  300. }
  301. catch (Exception)
  302. {
  303. }
  304. automaticMeasurement.PlotTheMeasurementRangeModels.hasUsed = true;
  305. automaticMeasurement.PlotTheMeasurementRangeModels.parameter1 = checkBox1.Checked;
  306. automaticMeasurement.PlotTheMeasurementRangeModels.parameter2 = Interval;
  307. string filePath = Application.StartupPath + "\\Config\\Default\\ParameterSaving\\AutomaticMeasurement.xml";
  308. string porosityInfoXml = XmlSerializeHelper.XmlSerialize<AutomaticMeasurementModel>(automaticMeasurement);
  309. FileOperationHelper.WriteStringToFile(porosityInfoXml, filePath, FileMode.Create);
  310. this.timer1.Stop();
  311. #region [清空内存]
  312. originalPictures.Clear();
  313. oldOriginalPictures.Clear();
  314. //pictures.Clear();
  315. BitmapArray.Clear();
  316. GC.Collect();
  317. #endregion
  318. }
  319. #endregion
  320. private bool lastPicture(Keys keys)
  321. {
  322. if (this.listPictureName.SelectedIndex == 0)
  323. {
  324. this.listPictureName.SelectedIndex = this.listPictureName.Items.Count - 1;
  325. }
  326. else {
  327. this.listPictureName.SelectedIndex -= 1;
  328. }
  329. return true;
  330. }
  331. private bool nextPicture(Keys keys)
  332. {
  333. if (this.listPictureName.SelectedIndex == this.listPictureName.Items.Count - 1)
  334. {
  335. this.listPictureName.SelectedIndex = 0;
  336. }
  337. else
  338. {
  339. this.listPictureName.SelectedIndex += 1;
  340. }
  341. return true;
  342. }
  343. private void documentWorkspace_panel_MouseMove(object sender, MouseEventArgs e)
  344. {
  345. if (this.startSpin)
  346. {
  347. return;
  348. }
  349. }
  350. private bool OneDataOnDeleteHotKeyPressed(Keys keys)
  351. {
  352. if (this.listPictureName.SelectedItem != null)
  353. {
  354. this.documentWorkspace.GraphicsList.Clear();
  355. if (this.dataList.ContainsKey(this.listPictureName.SelectedIndex)) {
  356. this.dataList[this.listPictureName.SelectedIndex].Clear();
  357. }
  358. this.documentWorkspace.Refresh();
  359. }
  360. return true;
  361. }
  362. private bool OnDeleteHotKeyPressed(Keys keys)
  363. {
  364. this.documentWorkspace.GraphicsList.Clear();
  365. foreach (var item in dataList)
  366. {
  367. item.Value.Clear();
  368. }
  369. this.documentWorkspace.Refresh();
  370. if (this.startSpin)
  371. {
  372. this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.DrawLine;
  373. }
  374. else {
  375. this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.ViewRectangle;
  376. }
  377. return true;
  378. }
  379. private void documentWorkspace_panel_MouseUp(object sender, MouseEventArgs e)
  380. {
  381. #region [旋转]
  382. if (this.startSpin)
  383. {
  384. if (e.Button == MouseButtons.Left)
  385. {
  386. double angle = 0;
  387. int removeIndex = -1;
  388. for (int i = 0; i < this.documentWorkspace.GraphicsList.Count; i++)
  389. {
  390. if (this.documentWorkspace.GraphicsList[i].objectType != Annotation.Enum.DrawClass.Label)
  391. {
  392. continue;
  393. }
  394. if (this.documentWorkspace.GraphicsList[i].startPoint.X <= this.documentWorkspace.GraphicsList[i].endPoint.X)
  395. {
  396. this.startPoint = this.documentWorkspace.GraphicsList[i].startPoint;
  397. this.endPoint = this.documentWorkspace.GraphicsList[i].endPoint;
  398. }
  399. else {
  400. this.startPoint = this.documentWorkspace.GraphicsList[i].endPoint;
  401. this.endPoint = this.documentWorkspace.GraphicsList[i].startPoint;
  402. }
  403. angle = BasicCalculationHelper.Angle(startPoint, endPoint, new PointF(startPoint.X, endPoint.Y));
  404. removeIndex = i;
  405. }
  406. angle = 0 - angle + this.hasAngle;
  407. this.hasAngle = angle;
  408. ParamObject action = new Data.Action.Action5017();
  409. for (int i = 0; i < action.Lists.Count; i++)
  410. {
  411. if (action.Lists[i] is DecimalNumber)
  412. {
  413. action.Lists[i].value = angle;
  414. }
  415. }
  416. Bitmap bitmap = (Bitmap)this.oldOriginalPictures[this.selectedIndex].Clone();
  417. Mat mat = action.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap));
  418. Bitmap newbitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
  419. pictures[this.selectedIndex] = newbitmap;
  420. this.originalPictures[this.selectedIndex] = newbitmap;
  421. if (removeIndex != -1)
  422. {
  423. this.documentWorkspace.GraphicsList.RemoveAt(removeIndex);
  424. this.documentWorkspace.Refresh();
  425. }
  426. #region [清空内存]
  427. if (bitmap != null)
  428. {
  429. bitmap.Dispose();
  430. }
  431. //if (newbitmap != null)
  432. //{
  433. // newbitmap.Dispose();
  434. //}
  435. //if (mat != null)
  436. //{
  437. // mat.Dispose();
  438. //}
  439. #endregion
  440. }
  441. else if (e.Button == MouseButtons.Right)
  442. {
  443. pictures[this.selectedIndex] = this.oldOriginalPictures[this.selectedIndex];
  444. this.originalPictures[this.selectedIndex] = this.oldOriginalPictures[this.selectedIndex];
  445. this.hasAngle = 0;
  446. }
  447. this.bitmap = pictures[this.selectedIndex];
  448. Document document = Document.FromImage(this.bitmap);
  449. this.documentWorkspace.Document = document;
  450. this.documentWorkspace.Visible = true;
  451. return;
  452. }
  453. #endregion
  454. GraphicsList graphicsList = new GraphicsList();
  455. int removeData = -1;
  456. for (int i = 0; i < this.documentWorkspace.GraphicsList.Count; i++)
  457. {
  458. if (this.documentWorkspace.GraphicsList[i].Width <= 100 && this.documentWorkspace.GraphicsList[i].Height <= 100)
  459. {
  460. removeData = i;
  461. continue;
  462. }
  463. graphicsList.Add(this.documentWorkspace.GraphicsList[i].Clone(this.documentWorkspace));
  464. }
  465. if (removeData != -1)
  466. {
  467. this.documentWorkspace.GraphicsList.RemoveAt(removeData);
  468. this.documentWorkspace.SetContinuousDrawingVoid(true);
  469. this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.ViewRectangle;
  470. this.documentWorkspace.Refresh();
  471. return;
  472. }
  473. if (e.Button == MouseButtons.Left)
  474. {
  475. for (int i = 0; i < this.listPictureName.Items.Count; i++)
  476. {
  477. if (this.dataList.ContainsKey(i))
  478. {
  479. this.dataList[i] = graphicsList;
  480. }
  481. else
  482. {
  483. this.dataList.Add(i, graphicsList);
  484. }
  485. }
  486. }
  487. else if (e.Button == MouseButtons.Right)
  488. {
  489. if (this.listPictureName.SelectedItem != null)
  490. {
  491. if (this.dataList.ContainsKey(this.listPictureName.SelectedIndex))
  492. {
  493. this.dataList[this.listPictureName.SelectedIndex] = graphicsList;
  494. }
  495. else
  496. {
  497. this.dataList.Add(this.listPictureName.SelectedIndex, graphicsList);
  498. }
  499. }
  500. if (isPlay)
  501. {
  502. timer1.Start();
  503. }
  504. }
  505. if (this.checkBox1.Checked)
  506. {
  507. if (isPlay)
  508. {
  509. timer1.Start();
  510. }
  511. }
  512. }
  513. /// <summary>
  514. ///
  515. /// </summary>
  516. /// <param name="sender"></param>
  517. /// <param name="e"></param>
  518. private void documentWorkspace_panel_MouseDown(object sender, MouseEventArgs e)
  519. {
  520. if (this.startSpin)
  521. {
  522. this.documentWorkspace.tools[(int)(this.documentWorkspace.activeTool)].InvokeMember("OnMouseDown",
  523. BindingFlags.Public |
  524. BindingFlags.Static |
  525. BindingFlags.InvokeMethod,
  526. null,
  527. null,
  528. new object[2] { this.documentWorkspace, e });
  529. return;
  530. }
  531. if (this.documentWorkspace.GraphicsList.Count > 0)
  532. {
  533. this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.Pointer;
  534. this.documentWorkspace.SetContinuousDrawingVoid(false);
  535. this.documentWorkspace.tools[(int)(this.documentWorkspace.activeTool)].InvokeMember("OnMouseDown",
  536. BindingFlags.Public |
  537. BindingFlags.Static |
  538. BindingFlags.InvokeMethod,
  539. null,
  540. null,
  541. new object[2] { this.documentWorkspace, e });
  542. var baseData = (ViewRectangle)this.documentWorkspace.GraphicsList[this.documentWorkspace.GraphicsList.Count - 1];
  543. if (!baseData.isHitTest)
  544. {
  545. this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.ViewRectangle;
  546. this.documentWorkspace.SetContinuousDrawingVoid(true);
  547. this.documentWorkspace.GraphicsList.RemoveAt(this.documentWorkspace.GraphicsList.Count - 1);
  548. }
  549. }
  550. this.documentWorkspace.tools[(int)(this.documentWorkspace.activeTool)].InvokeMember("OnMouseDown",
  551. BindingFlags.Public |
  552. BindingFlags.Static |
  553. BindingFlags.InvokeMethod,
  554. null,
  555. null,
  556. new object[2] { this.documentWorkspace, e });
  557. if (isPlay)
  558. {
  559. if (this.checkBox1.Checked || e.Button == MouseButtons.Right)
  560. {
  561. timer1.Stop();
  562. }
  563. else
  564. {
  565. GraphicsList graphicsList = new GraphicsList();
  566. for (int i = 0; i < this.documentWorkspace.GraphicsList.Count; i++)
  567. {
  568. graphicsList.Add(this.documentWorkspace.GraphicsList[i].Clone(this.documentWorkspace));
  569. }
  570. if (e.Button == MouseButtons.Left)
  571. {
  572. for (int i = 0; i < this.listPictureName.Items.Count; i++)
  573. {
  574. if (this.dataList.ContainsKey(i))
  575. {
  576. this.dataList[i] = graphicsList;
  577. }
  578. else
  579. {
  580. this.dataList.Add(i, graphicsList);
  581. }
  582. }
  583. }
  584. else if (e.Button == MouseButtons.Right)
  585. {
  586. if (this.listPictureName.SelectedItem != null)
  587. {
  588. if (this.dataList.ContainsKey(this.listPictureName.SelectedIndex))
  589. {
  590. this.dataList[this.listPictureName.SelectedIndex] = graphicsList;
  591. }
  592. else
  593. {
  594. this.dataList.Add(this.listPictureName.SelectedIndex, graphicsList);
  595. }
  596. }
  597. }
  598. }
  599. }
  600. }
  601. #region 公共按钮
  602. private void InitCommonButtonEvent()
  603. {
  604. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  605. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  606. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  607. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  608. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  609. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  610. this.commonControlButtons.isModeCheckBox.CheckedChanged += new EventHandler(isModeCheckBox_Click);
  611. }
  612. private void isModeCheckBox_Click(object sender, EventArgs e)
  613. {
  614. if (!this.isNormal)
  615. {//叠加
  616. int daodianbuCount = this.dataBoolList.Keys.Count;
  617. int fanweiCount = this.dataIsFanweibuchangList.Keys.Count;
  618. int erzhiCount = this.dataIsErzhichuliList.Keys.Count;
  619. if (!isFanweiCheckBox && !isErzhiCheckBox && daodianbuCount >0)
  620. for (int index = 0; index < daodianbuCount; index++)
  621. {
  622. if (this.dataBoolList.ContainsKey(index))
  623. {
  624. this.dataBoolList[index] = this.commonControlButtons.isModeCheckBox.Checked;
  625. }
  626. else
  627. {
  628. this.dataBoolList.Add(index, this.commonControlButtons.isModeCheckBox.Checked);
  629. }
  630. }
  631. if (isFanweiCheckBox && fanweiCount > 0)
  632. for (int index = 0; index < fanweiCount; index++)
  633. {
  634. if (this.dataIsFanweibuchangList.ContainsKey(index))
  635. {
  636. this.dataIsFanweibuchangList[index] = this.commonControlButtons.isModeCheckBox.Checked;
  637. }
  638. else
  639. {
  640. this.dataIsFanweibuchangList.Add(index, this.commonControlButtons.isModeCheckBox.Checked);
  641. }
  642. }
  643. if (isErzhiCheckBox && erzhiCount > 0)
  644. for (int index = 0; index < erzhiCount; index++)
  645. {
  646. if (this.dataIsErzhichuliList.ContainsKey(index))
  647. {
  648. this.dataIsErzhichuliList[index] = this.commonControlButtons.isModeCheckBox.Checked;
  649. }
  650. else
  651. {
  652. this.dataIsErzhichuliList.Add(index, this.commonControlButtons.isModeCheckBox.Checked);
  653. }
  654. }
  655. return;
  656. }
  657. if (this.listPictureName.SelectedItem != null)
  658. {
  659. int index = listPictureName.SelectedIndex;
  660. if (!isFanweiCheckBox && !isErzhiCheckBox)
  661. if (this.dataBoolList.ContainsKey(index))
  662. {
  663. this.dataBoolList[index] = this.commonControlButtons.isModeCheckBox.Checked;
  664. }
  665. else
  666. {
  667. this.dataBoolList.Add(index, this.commonControlButtons.isModeCheckBox.Checked);
  668. }
  669. if (isFanweiCheckBox)
  670. if (this.dataIsFanweibuchangList.ContainsKey(index))
  671. {
  672. this.dataIsFanweibuchangList[index] = this.commonControlButtons.isModeCheckBox.Checked;
  673. }
  674. else
  675. {
  676. this.dataIsFanweibuchangList.Add(index, this.commonControlButtons.isModeCheckBox.Checked);
  677. }
  678. if (isErzhiCheckBox)
  679. if (this.dataIsErzhichuliList.ContainsKey(index))
  680. {
  681. this.dataIsErzhichuliList[index] = this.commonControlButtons.isModeCheckBox.Checked;
  682. }
  683. else
  684. {
  685. this.dataIsErzhichuliList.Add(index, this.commonControlButtons.isModeCheckBox.Checked);
  686. }
  687. }
  688. }
  689. private void zoomInButton_Click(object sender, EventArgs e)
  690. {
  691. if (this.bitmap != null)
  692. this.documentWorkspace.ZoomIn();
  693. }
  694. private void zoomOutButton_Click(object sender, EventArgs e)
  695. {
  696. if (this.bitmap != null)
  697. this.documentWorkspace.ZoomOut();
  698. }
  699. private void zoomToWindowButton_Click(object sender, EventArgs e)
  700. {
  701. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  702. }
  703. private void actualSizeButton_Click(object sender, EventArgs e)
  704. {
  705. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  706. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  707. }
  708. private void pointerButton_Click(object sender, EventArgs e)
  709. {
  710. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
  711. }
  712. private void mobileModeButton_Click(object sender, EventArgs e)
  713. {
  714. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  715. }
  716. #endregion
  717. private void PlotTheMeasurementRange_Load()
  718. {
  719. listPictureName.DataSource = null;
  720. listPictureName.DataSource = pictureNames;
  721. }
  722. private void listPictureName_MouseDown(object sender, EventArgs e)
  723. {
  724. if (this.listPictureName.SelectedItem != null)
  725. {
  726. if (this.selectedIndex == this.listPictureName.SelectedIndex)
  727. {
  728. return;
  729. }
  730. this.hasAngle = 0;
  731. GraphicsList graphicsList = new GraphicsList();
  732. index = listPictureName.SelectedIndex;
  733. this.selectedIndex = index;
  734. if (!this.isPlay)
  735. {
  736. if (index + 1 != this.triangleTrackBar1.Value)
  737. {
  738. this.listPictureName.SelectedValueChanged -= new System.EventHandler(this.listPictureName_MouseDown);
  739. this.triangleTrackBar1.Value = index + 1;
  740. this.textBox1.Text = this.triangleTrackBar1.Value + @"/" + this.triangleTrackBar1.Maximum;
  741. this.listPictureName.SelectedValueChanged += new System.EventHandler(this.listPictureName_MouseDown);
  742. }
  743. }
  744. if (!isFanweiCheckBox && !isErzhiCheckBox)
  745. if (this.dataBoolList.ContainsKey(index))
  746. {
  747. bool isCheck;
  748. this.dataBoolList.TryGetValue(index, out isCheck);
  749. if (isCheck)
  750. {
  751. this.commonControlButtons.isModeCheckBox.Checked = true;
  752. }
  753. else
  754. {
  755. this.commonControlButtons.isModeCheckBox.Checked = false;
  756. }
  757. }
  758. if (isFanweiCheckBox)
  759. if (this.dataIsFanweibuchangList.ContainsKey(index))
  760. {
  761. bool isCheck;
  762. this.dataIsFanweibuchangList.TryGetValue(index, out isCheck);
  763. if (isCheck)
  764. {
  765. this.commonControlButtons.isModeCheckBox.Checked = true;
  766. }
  767. else
  768. {
  769. this.commonControlButtons.isModeCheckBox.Checked = false;
  770. }
  771. }
  772. if (isErzhiCheckBox)
  773. if (this.dataIsErzhichuliList.ContainsKey(index))
  774. {
  775. bool isCheck;
  776. this.dataIsErzhichuliList.TryGetValue(index, out isCheck);
  777. if (isCheck)
  778. {
  779. this.commonControlButtons.isModeCheckBox.Checked = true;
  780. }
  781. else
  782. {
  783. this.commonControlButtons.isModeCheckBox.Checked = false;
  784. }
  785. }
  786. if (index < 0 || index >= pictures.Count)
  787. {
  788. return;
  789. }
  790. #region [判断透明度]
  791. if (this.isNormal)
  792. {
  793. int num = 255;
  794. try
  795. {
  796. num = Convert.ToInt32(textBox3.Text);
  797. if (num > 255)
  798. {
  799. num = 255;
  800. textBox3.Text = "255";
  801. }
  802. }
  803. catch (Exception)
  804. {
  805. }
  806. this.BitmapArray.Clear();
  807. var abc = (Bitmap)originalPictures[index].Clone();
  808. Bitmap map = MakeTransparent(abc, num);
  809. if (map != null)
  810. {
  811. this.BitmapArray.Add(map);
  812. this.BitmapArray.Add(map);
  813. this.OverlapHeight = this.BitmapArray[0].Height;
  814. this.OverlapWidth = this.BitmapArray[0].Width;
  815. pictures[index] = Overlap(OverlapType.CENTER);
  816. }
  817. if (abc != null)
  818. {
  819. abc.Dispose();
  820. }
  821. }
  822. #endregion
  823. if (this.startSpin)
  824. {
  825. this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.DrawLine;
  826. }
  827. else {
  828. this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.ViewRectangle;
  829. }
  830. this.bitmap = pictures[index];
  831. Document document = Document.FromImage(this.bitmap);
  832. this.documentWorkspace.Document = document;
  833. this.documentWorkspace.Visible = true;
  834. if (this.dataList.ContainsKey(index))
  835. {
  836. for (int i = 0; i < this.dataList[index].Count; i++)
  837. {
  838. graphicsList.Add(this.dataList[index][i].Clone(this.documentWorkspace));
  839. }
  840. this.documentWorkspace.GraphicsList = graphicsList;
  841. }
  842. else
  843. {
  844. this.documentWorkspace.GraphicsList = graphicsList;
  845. }
  846. this.documentWorkspace.Refresh();
  847. groupBoxZhangshu.Text = "第" + (index + 1).ToString() + PdnResources.GetString("NewZhang");
  848. }
  849. }
  850. /// <summary>
  851. /// 确定
  852. /// </summary>
  853. /// <param name="sender"></param>
  854. /// <param name="e"></param>
  855. private void buttonOKDraw_Click(object sender, EventArgs e)
  856. {
  857. if (this.listPictureName.SelectedItem != null)
  858. {
  859. index = listPictureName.SelectedIndex;
  860. GraphicsList graphicsList = new GraphicsList();
  861. for (int i = 0; i < this.documentWorkspace.GraphicsList.Count; i++)
  862. {
  863. graphicsList.Add(this.documentWorkspace.GraphicsList[i].Clone(this.documentWorkspace));
  864. }
  865. if (this.dataList.ContainsKey(index))
  866. {
  867. this.dataList[index] = graphicsList;
  868. }
  869. else
  870. {
  871. this.dataList.Add(index, graphicsList);
  872. }
  873. }
  874. for (int i = 0; i < this.listPictureName.Items.Count; i++)
  875. if (!this.dataList.ContainsKey(i))//避免空数据导致的后续bug
  876. this.dataList.Add(i, new GraphicsList());
  877. this.AutomaticMeasurement.getList(this.dataList, thisindex);
  878. this.AutomaticMeasurement.getBoolList(this.dataBoolList, thisindex);
  879. if (isFanweiCheckBox) this.AutomaticMeasurement.getIsFanweibuchangList(this.dataIsFanweibuchangList, thisindex);
  880. if (isErzhiCheckBox) this.AutomaticMeasurement.getIsErzhichuliList(this.dataIsErzhichuliList, thisindex);
  881. this.Close();
  882. }
  883. #region [播放相关]
  884. /// <summary>
  885. /// 图片选择改变
  886. /// </summary>
  887. /// <param name="sender"></param>
  888. /// <param name="e"></param>
  889. private void trackBar_Scroll(object sender, EventArgs e)
  890. {
  891. this.textBox1.Text = this.triangleTrackBar1.Value + @"/" + this.triangleTrackBar1.Maximum;
  892. try
  893. {
  894. //滚动到指定的行位置
  895. this.listPictureName.SelectedIndex = this.triangleTrackBar1.Value - 1;
  896. }
  897. catch (Exception ex)
  898. {
  899. this.listPictureName.SelectedIndex = 0;
  900. }
  901. }
  902. #endregion
  903. /// <summary>
  904. /// 从后往前播放按钮
  905. /// </summary>
  906. /// <param name="sender"></param>
  907. /// <param name="e"></param>
  908. private void button1_Click(object sender, EventArgs e)
  909. {
  910. if (this.startSpin)
  911. {
  912. return;
  913. }
  914. if (this.button1.BackColor == Color.DarkGray)
  915. return;
  916. else
  917. {
  918. this.button1.BackColor = Color.DarkGray;
  919. this.button2.BackColor = Color.FromArgb(255, 240, 240, 240);
  920. this.playType = 1;
  921. }
  922. }
  923. /// <summary>
  924. /// 从前往后播放按钮
  925. /// </summary>
  926. /// <param name="sender"></param>
  927. /// <param name="e"></param>
  928. private void button2_Click(object sender, EventArgs e)
  929. {
  930. if (this.startSpin)
  931. {
  932. return;
  933. }
  934. if (this.button2.BackColor == Color.DarkGray)
  935. return;
  936. else
  937. {
  938. this.button2.BackColor = Color.DarkGray;
  939. this.button1.BackColor = Color.FromArgb(255, 240, 240, 240);
  940. this.playType = 2;
  941. }
  942. }
  943. /// <summary>
  944. /// 是否循环播放
  945. /// </summary>
  946. /// <param name="sender"></param>
  947. /// <param name="e"></param>
  948. private void button3_Click(object sender, EventArgs e)
  949. {
  950. if (this.startSpin)
  951. {
  952. return;
  953. }
  954. if (this.button3.BackColor == Color.DarkGray)
  955. {
  956. this.button3.BackColor = Color.FromArgb(255, 240, 240, 240);
  957. this.isLoop = false;
  958. }
  959. else
  960. {
  961. this.button3.BackColor = Color.DarkGray;
  962. this.isLoop = true;
  963. }
  964. }
  965. /// <summary>
  966. /// 播放 暂停
  967. /// </summary>
  968. /// <param name="sender"></param>
  969. /// <param name="e"></param>
  970. private void button4_Click(object sender, EventArgs e)
  971. {
  972. if (this.startSpin)
  973. {
  974. MessageBox.Show("旋轉模式中,請勿播放!");
  975. return;
  976. }
  977. if (this.isPlay)
  978. {
  979. this.button4.Image = PdnResources.GetImageResource("Icons.MultiNowPlayIcon.png").Reference;
  980. this.isPlay = false;
  981. this.timer1.Stop();
  982. }
  983. else
  984. {
  985. this.button4.Image = PdnResources.GetImageResource("Icons.MultiNowPauseIcon.png").Reference;
  986. this.isPlay = true;
  987. this.timer1.Start();
  988. }
  989. }
  990. /// <summary>
  991. /// 开始播放
  992. /// </summary>
  993. /// <param name="sender"></param>
  994. /// <param name="e"></param>
  995. private void timer1_Tick(object sender, EventArgs e)
  996. {
  997. if (this.playType == 2)
  998. {
  999. if (this.selectedIndex < this.listPictureName.Items.Count - 1)
  1000. {
  1001. this.listPictureName.SelectedIndex = this.selectedIndex + 1;
  1002. this.triangleTrackBar1.Value = this.selectedIndex + 1;
  1003. }
  1004. else
  1005. {
  1006. if (this.isLoop)
  1007. {
  1008. this.listPictureName.SelectedIndex = 0;
  1009. this.triangleTrackBar1.Value = 1;
  1010. }
  1011. else {
  1012. this.isPlay = false;
  1013. this.timer1.Stop();
  1014. this.button4.Image = PdnResources.GetImageResource("Icons.MultiNowPlayIcon.png").Reference;
  1015. }
  1016. }
  1017. }
  1018. else {
  1019. if (this.selectedIndex > 0)
  1020. {
  1021. int index = this.selectedIndex;
  1022. this.listPictureName.SelectedIndex = this.selectedIndex - 1;
  1023. this.triangleTrackBar1.Value = index;
  1024. }
  1025. else
  1026. {
  1027. if (this.isLoop)
  1028. {
  1029. this.listPictureName.SelectedIndex = this.listPictureName.Items.Count - 1;
  1030. this.triangleTrackBar1.Value = this.listPictureName.Items.Count;
  1031. }
  1032. else
  1033. {
  1034. this.isPlay = false;
  1035. this.timer1.Stop();
  1036. this.button4.Image = PdnResources.GetImageResource("Icons.MultiNowPlayIcon.png").Reference;
  1037. }
  1038. }
  1039. }
  1040. this.textBox1.Text = this.triangleTrackBar1.Value + @"/" + this.triangleTrackBar1.Maximum;
  1041. }
  1042. public Bitmap Overlap(OverlapType type)
  1043. {
  1044. Bitmap bmPhoto;
  1045. try
  1046. {
  1047. Bitmap[] bitmaps = this.BitmapArray.ToArray();
  1048. int width = this.OverlapWidth;
  1049. int height = this.OverlapHeight;
  1050. if (width == 0 || height == 0)
  1051. {
  1052. return null;
  1053. }
  1054. Mat mat = new Mat(height, width, MatType.CV_8UC4, new Scalar(240, 240, 240, 255));
  1055. bmPhoto = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
  1056. float x = 0;
  1057. float y = 0;
  1058. //load the Bitmap into a Graphics object
  1059. Graphics grPhoto = Graphics.FromImage(bmPhoto);
  1060. //Set the rendering quality for this Graphics object
  1061. grPhoto.SmoothingMode = SmoothingMode.AntiAlias;//清除锯齿的呈现
  1062. //haix
  1063. for (int i = 0; i < bitmaps.Length; i++)
  1064. {
  1065. Bitmap img = bitmaps[i];
  1066. if (img == null)
  1067. {
  1068. continue;
  1069. }
  1070. if (type == OverlapType.CENTER)
  1071. {
  1072. x = (width - img.Width) / 2.0f;
  1073. y = (height - img.Height) / 2.0f;
  1074. if (i == 1)
  1075. {
  1076. x += 1;
  1077. y += 1;
  1078. }
  1079. }
  1080. grPhoto.DrawImage(img, 0,0,img.Width, img.Height);
  1081. }
  1082. if (mat != null)
  1083. {
  1084. mat.Dispose();
  1085. }
  1086. }
  1087. catch (Exception)
  1088. {
  1089. return null;
  1090. }
  1091. return bmPhoto;
  1092. }
  1093. //定义图像透明度调整函数
  1094. public Bitmap MakeTransparent(Bitmap src, int num)
  1095. {
  1096. return ImageTools.MakeTransparent(src, num);
  1097. }
  1098. /// <summary>
  1099. /// 透明度修改
  1100. /// </summary>
  1101. /// <param name="sender"></param>
  1102. /// <param name="e"></param>
  1103. private void textBox3_TextChanged(object sender, KeyEventArgs e)
  1104. {
  1105. if (this.startSpin)
  1106. {
  1107. return;
  1108. }
  1109. if (e.KeyCode == Keys.Control || e.KeyCode == Keys.Enter)
  1110. {
  1111. if (this.isNormal)
  1112. {
  1113. int num = 255;
  1114. try
  1115. {
  1116. num = Convert.ToInt32(textBox3.Text);
  1117. if (num > 255)
  1118. {
  1119. num = 255;
  1120. textBox3.Text = "255";
  1121. }
  1122. }
  1123. catch (Exception)
  1124. {
  1125. }
  1126. this.BitmapArray.Clear();
  1127. var abc = (Bitmap)originalPictures[this.selectedIndex].Clone();
  1128. Bitmap map = MakeTransparent(abc, num);
  1129. this.BitmapArray.Add(map);
  1130. this.BitmapArray.Add(map);
  1131. pictures[this.selectedIndex] = Overlap(OverlapType.CENTER);
  1132. abc.Dispose();
  1133. this.bitmap = pictures[this.selectedIndex];
  1134. Document document = Document.FromImage(this.bitmap);
  1135. this.documentWorkspace.Document = document;
  1136. this.documentWorkspace.Visible = true;
  1137. }
  1138. else {
  1139. int num = 255 / this.listPictureName.Items.Count;
  1140. try
  1141. {
  1142. num = Convert.ToInt32(textBox3.Text);
  1143. if (num > 255)
  1144. {
  1145. num = 255;
  1146. textBox3.Text = "255";
  1147. }
  1148. }
  1149. catch (Exception)
  1150. {
  1151. }
  1152. this.BitmapArray.Clear();
  1153. foreach (Bitmap item in originalPictures)
  1154. {
  1155. Bitmap cloneData = (Bitmap)item.Clone();
  1156. Bitmap bitmap = MakeTransparent(cloneData, num);
  1157. this.BitmapArray.Add(bitmap);
  1158. cloneData.Dispose();
  1159. }
  1160. this.OverlapHeight = this.BitmapArray[0].Height;
  1161. this.OverlapWidth = this.BitmapArray[0].Width;
  1162. this.bitmap = Overlap(OverlapType.CENTER);
  1163. Document document = Document.FromImage(this.bitmap);
  1164. this.documentWorkspace.Document = document;
  1165. this.documentWorkspace.Visible = true;
  1166. }
  1167. }
  1168. }
  1169. /// <summary>
  1170. /// 时间间隔修改
  1171. /// </summary>
  1172. /// <param name="sender"></param>
  1173. /// <param name="e"></param>
  1174. private void textBox2_TextChanged(object sender, KeyEventArgs e)
  1175. {
  1176. if (this.startSpin)
  1177. {
  1178. return;
  1179. }
  1180. if (e.KeyCode == Keys.Control || e.KeyCode == Keys.Enter)
  1181. {
  1182. int Interval = 1000;
  1183. try
  1184. {
  1185. Interval = Convert.ToInt32(textBox2.Text);
  1186. }
  1187. catch (Exception)
  1188. {
  1189. }
  1190. timer1.Interval = Interval;
  1191. }
  1192. }
  1193. /// <summary>
  1194. /// 正常
  1195. /// </summary>
  1196. /// <param name="sender"></param>
  1197. /// <param name="e"></param>
  1198. private void button5_Click(object sender, EventArgs e)
  1199. {
  1200. if (this.startSpin)
  1201. {
  1202. this.startSpin = false;
  1203. this.button7.Text = "旋转";
  1204. }
  1205. this.textBox3.Text = "255";
  1206. this.listPictureName.Enabled = true;
  1207. this.selectedIndex = -1;
  1208. this.isNormal = true;
  1209. this.BitmapArray.Clear();
  1210. for (int i = 0; i <= originalPictures.Count - 1; i++)
  1211. {
  1212. var abc = (Bitmap)originalPictures[i].Clone();
  1213. Bitmap map = MakeTransparent(abc, 255);
  1214. this.BitmapArray.Add(map);
  1215. this.OverlapHeight = this.BitmapArray[0].Height;
  1216. this.OverlapWidth = this.BitmapArray[0].Width;
  1217. pictures[i] = Overlap(OverlapType.CENTER);
  1218. abc.Dispose();
  1219. }
  1220. this.listPictureName_MouseDown(null, null);
  1221. }
  1222. /// <summary>
  1223. /// 叠加
  1224. /// </summary>
  1225. /// <param name="sender"></param>
  1226. /// <param name="e"></param>
  1227. private void button6_Click(object sender, EventArgs e)
  1228. {
  1229. if (this.startSpin)
  1230. {
  1231. this.startSpin = false;
  1232. this.button7.Text = "旋转";
  1233. }
  1234. if (this.documentWorkspace.activeTool != Annotation.Enum.DrawToolType.ViewRectangle)
  1235. {
  1236. this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.ViewRectangle;
  1237. this.documentWorkspace.SetContinuousDrawingVoid(true);
  1238. }
  1239. var num = Convert.ToInt32(255 / this.listPictureName.Items.Count);
  1240. this.textBox3.Text = num.ToString();
  1241. this.listPictureName.Enabled = false;
  1242. this.BitmapArray.Clear();
  1243. foreach (Bitmap item in originalPictures)
  1244. {
  1245. Bitmap cloneData = (Bitmap)item.Clone();
  1246. Bitmap bitmap = MakeTransparent(cloneData, num);
  1247. this.BitmapArray.Add(bitmap);
  1248. cloneData.Dispose();
  1249. }
  1250. this.OverlapHeight = this.BitmapArray[0].Height;
  1251. this.OverlapWidth = this.BitmapArray[0].Width;
  1252. this.bitmap = Overlap(OverlapType.CENTER);
  1253. Document document = Document.FromImage(this.bitmap);
  1254. this.documentWorkspace.Document = document;
  1255. this.documentWorkspace.Visible = true;
  1256. if (this.isPlay)
  1257. {
  1258. this.button4.Image = PdnResources.GetImageResource("Icons.MultiNowPlayIcon.png").Reference;
  1259. this.isPlay = false;
  1260. this.timer1.Stop();
  1261. }
  1262. this.isNormal = false;
  1263. GC.Collect();
  1264. }
  1265. /// <summary>
  1266. /// 旋转开始
  1267. /// </summary>
  1268. /// <param name="sender"></param>
  1269. /// <param name="e"></param>
  1270. private void button7_Click(object sender, EventArgs e)
  1271. {
  1272. if (this.isPlay)
  1273. {
  1274. return;
  1275. }
  1276. this.startSpin = !this.startSpin;
  1277. if (this.startSpin)
  1278. {
  1279. this.button7.Text = "停止旋转";
  1280. this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.DrawLine;
  1281. }
  1282. else {
  1283. this.button7.Text = "旋转";
  1284. this.documentWorkspace.activeTool = Annotation.Enum.DrawToolType.ViewRectangle;
  1285. }
  1286. }
  1287. }
  1288. }