ResultsViewRange.cs 56 KB

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