图像标记_3_10_2
还差:标记图片修改,快捷键自定义,窗口大小自动收放
1 using System; 2 using System.IO; 3 using System.Collections.Generic; 4 using System.ComponentModel; 5 using System.Data; 6 using System.Drawing; 7 using System.Linq; 8 using System.Text; 9 using System.Threading.Tasks; 10 using System.Windows.Forms; 11 using System.Xml; 12 13 namespace Image_mark 14 { 15 16 public partial class Form1 : Form 17 { 18 // 我设置的全局变量 19 private List<string> all_picture_path = new List<string>(); 20 private List<string> all_picture_name = new List<string>(); 21 private string current_picture_path; 22 private int current_picture_index = 0; // 从1开始 23 24 private List<string> all_type_picture_path = new List<string>(); 25 private string current_type_picture_path = ""; 26 27 private List<string> all_join_picture_path = new List<string>(); 28 29 private ImageList join_image_list = new ImageList(); 30 private List<string> join_image_list_name = new List<string>(); 31 private List<string> join_image_list_path = new List<string>(); 32 private const int show_join_image_num = 4; 33 private Button[] show_join_image_button = new Button[show_join_image_num]; 34 35 private int function_select = 0; 36 private const int BROW = 1; 37 private const int EYE = 2; 38 private const int NOSE = 3; 39 private const int MOUTH = 4; 40 41 private int xml_node_num = 0; 42 private bool load_xml_ok = false; 43 44 private string brow_tpye_path = @".\brow\"; 45 private string eye_tpye_path = @".\eye\"; 46 private string nose_tpye_path = @".\nose\"; 47 private string mouth_tpye_path = @".\mouth\"; 48 49 private Button[] type_button = new Button[20]; 50 private const int type_button_WIDTH = 100; 51 private const int type_button_HEIGHT = 50; 52 private const int type_button_1_location_x = 450; 53 private const int type_button_1_location_y = 70; 54 55 Keys[] key_type = new Keys[9]; 56 57 58 private Auto_size_form auto_size_form = new Auto_size_form(); 59 60 61 #region 构造函数,初始化 62 public Form1() 63 { 64 InitializeComponent(); 65 66 Init(); 67 68 } 69 #endregion 70 71 private void Init() 72 {// 一些初始化 73 74 key_type[0] = Keys.NumPad7; 75 key_type[1] = Keys.NumPad8; 76 key_type[2] = Keys.NumPad9; 77 key_type[3] = Keys.NumPad4; 78 key_type[4] = Keys.NumPad5; 79 key_type[5] = Keys.NumPad6; 80 key_type[6] = Keys.NumPad1; 81 key_type[7] = Keys.NumPad2; 82 key_type[8] = Keys.NumPad3; 83 84 Set_show_join_image_button(); 85 86 Using_select_picture_button(false); 87 88 } 89 90 #region 设置4个回看按钮 91 private void Set_show_join_image_button() 92 { 93 int x = 10, y = 10; 94 int per_x_add = (this.groupBox2.Width - 10) / 4; 95 for (int i = 0; i < show_join_image_num; i++) 96 { 97 show_join_image_button[i] = new Button(); 98 show_join_image_button[i].Location = new Point(x, y); 99 show_join_image_button[i].Size = new Size(per_x_add - 10, this.groupBox2.Height - 20); 100 show_join_image_button[i].BackgroundImageLayout = ImageLayout.Stretch; 101 show_join_image_button[i].Name = ("joinButton" + i.ToString()); 102 show_join_image_button[i].Click += new System.EventHandler(this.join_image_button_Click); 103 104 this.groupBox2.Controls.Add(show_join_image_button[i]); 105 106 x += per_x_add; 107 } 108 109 } 110 #endregion 111 112 #region 根据标记功能加载相应的 XML 文件 设置按钮 113 private void Load_xml_set_button() 114 { 115 XmlDocument xmlDoc = new XmlDocument(); 116 XmlReaderSettings settings = new XmlReaderSettings(); 117 settings.IgnoreComments = true; 118 119 OpenFileDialog openFileDialog1 = new OpenFileDialog(); 120 121 openFileDialog1.InitialDirectory = @"E:\"; 122 openFileDialog1.Filter = "xml files (*.xml)|*.xml"; 123 openFileDialog1.RestoreDirectory = true; 124 125 // 先把之前的功能按钮释放 126 if(xml_node_num != 0) 127 { 128 for (int i = 0; i < xml_node_num; i++) 129 type_button[i].Dispose(); 130 } 131 132 // 移除之前的图片路径 133 all_type_picture_path.Clear(); 134 135 string xml_type = ""; 136 switch(function_select) 137 { 138 case BROW: 139 { 140 xml_type = "brow"; 141 current_type_picture_path = brow_tpye_path; 142 } break; 143 case EYE: 144 { 145 xml_type = "eye"; 146 current_type_picture_path = eye_tpye_path; 147 } break; 148 case NOSE: 149 { 150 xml_type = "nose"; 151 current_type_picture_path = nose_tpye_path; 152 } break; 153 case MOUTH: 154 { 155 xml_type = "mouth"; 156 current_type_picture_path = mouth_tpye_path; 157 } break; 158 } 159 160 if ((openFileDialog1.ShowDialog() == DialogResult.OK) && (openFileDialog1.FileName != "")) 161 { 162 string xml_path = openFileDialog1.FileName; 163 164 XmlReader reader = XmlReader.Create(xml_path, settings); 165 xmlDoc.Load(reader); 166 167 if (xmlDoc.DocumentElement.ChildNodes.Count <= 0) 168 { 169 MessageBox.Show("该 xml 无配置信息,请重新选择"); 170 return; 171 } 172 if (xmlDoc.DocumentElement.ChildNodes[0].Name != xml_type) 173 { 174 MessageBox.Show("该 xml 与标记功能不对应,请重新选择"); 175 return; 176 } 177 } 178 else 179 { 180 return; 181 } 182 183 // 标记类型样本数量 184 xml_node_num = xmlDoc.DocumentElement.ChildNodes.Count; 185 load_xml_ok = true; 186 187 for (int i = 0; i < xml_node_num; i++) 188 { 189 switch (function_select) 190 { 191 case BROW: 192 { 193 all_type_picture_path.Add( brow_tpye_path + 194 ((XmlElement)xmlDoc.DocumentElement.ChildNodes[i]).GetAttribute("type").ToString() + 195 ".jpg"); 196 197 } 198 break; 199 case EYE: 200 { 201 all_type_picture_path.Add( eye_tpye_path + 202 ((XmlElement)xmlDoc.DocumentElement.ChildNodes[i]).GetAttribute("type").ToString() + 203 ".jpg"); 204 } 205 break; 206 case NOSE: 207 { 208 all_type_picture_path.Add( nose_tpye_path + 209 ((XmlElement)xmlDoc.DocumentElement.ChildNodes[i]).GetAttribute("type").ToString() + 210 ".jpg"); 211 } 212 break; 213 case MOUTH: 214 { 215 all_type_picture_path.Add( mouth_tpye_path + 216 ((XmlElement)xmlDoc.DocumentElement.ChildNodes[i]).GetAttribute("type").ToString() + 217 ".jpg"); 218 } 219 break; 220 default: break; 221 } 222 } 223 224 int x = 10, y = 20; 225 int per_x_add = (this.groupBox1.Width - 10) / 3; 226 int per_y_add = (this.groupBox1.Height - 20) / 3; 227 int x_button_num = 0; 228 229 for (int i = 0; i < xml_node_num; i++) 230 { 231 type_button[i] = new Button(); 232 type_button[i].Location = new Point(x, y); 233 type_button[i].Size = new Size(per_x_add - 10, per_y_add - 10); 234 type_button[i].BackgroundImageLayout = ImageLayout.Stretch; 235 type_button[i].Name = ((XmlElement)xmlDoc.DocumentElement.ChildNodes[i]).GetAttribute("type").ToString(); 236 //type_button[i].Text = ((XmlElement)xmlDoc.DocumentElement.ChildNodes[i]).GetAttribute("type").ToString(); 237 type_button[i].BackgroundImage = Image.FromFile(all_type_picture_path[i]); 238 239 type_button[i].Click += new System.EventHandler(this.type_button_Click); 240 241 this.groupBox1.Controls.Add(type_button[i]); 242 243 x += per_x_add; 244 ++x_button_num; 245 if (x_button_num == 3) 246 { 247 x = 10; 248 x_button_num = 0; 249 y += per_y_add; 250 } 251 252 } 253 254 } 255 #endregion 256 257 258 #region 标记选项按钮消息 259 private void type_button_Click(object sender, EventArgs e) 260 { 261 if (Write_output_xml(sender) == 1) 262 { 263 for (int i = 0; i < xml_node_num; i++) 264 { 265 int len = all_type_picture_path[i].Length - current_type_picture_path.Length; 266 if (all_type_picture_path[i].Substring(all_type_picture_path[i].Length - len, len) == 267 (((Button)sender).Name + ".jpg")) 268 { 269 // 拼接图片 270 Join_image(sender, all_picture_path[current_picture_index - 1], all_type_picture_path[i]); 271 272 Show_join_image_in_button(); 273 274 } 275 276 } 277 } 278 // 自动开始下一张 279 Next_picture(); 280 281 } 282 #endregion 283 284 #region 写图片信息到 xml 输出文件 285 // 返回 0 表示已经标记过 286 private int Write_output_xml(object sender) 287 { 288 if (!File.Exists(@"output.xml")) 289 { 290 XmlTextWriter output_xml = new XmlTextWriter("output.xml", Encoding.UTF8); 291 output_xml.Formatting = Formatting.Indented; 292 output_xml.WriteStartDocument(false); 293 294 output_xml.WriteStartElement("图片标记信息"); 295 296 output_xml.WriteComment("这是使用软件标记后输出的图片信息"); 297 298 output_xml.WriteEndElement(); 299 300 output_xml.Flush(); 301 output_xml.Close(); 302 } 303 304 XmlDocument xmldoc = new XmlDocument(); 305 xmldoc.Load("output.xml"); 306 307 XmlNode root = xmldoc.SelectSingleNode("图片标记信息"); 308 309 switch(function_select) 310 { 311 case BROW: 312 { 313 if(if_mark_the_picture(root, function_select)) 314 { 315 MessageBox.Show("该图片此类型已经标记过"); 316 return 0; 317 } 318 319 // 查找xml中是否有当前图片信息,有的话不要创建节点,直接添加 320 XmlNodeList nodelist = root.ChildNodes; 321 if (nodelist.Count > 0) 322 { 323 foreach (XmlNode node1 in nodelist) 324 { 325 if (node1.Name == all_picture_name[current_picture_index - 1]) 326 { 327 node1.Attributes["brow_type"].Value = ((Button)sender).Name; 328 329 xmldoc.Save("output.xml"); 330 331 return 1; 332 } 333 } 334 } 335 336 //创建一个<Node>节点 337 XmlElement xe1 = xmldoc.CreateElement(all_picture_name[current_picture_index - 1]); 338 339 //设置该节点 type 属性 340 xe1.SetAttribute("brow_type", ((Button)sender).Name); 341 342 if (xe1.Attributes["eye_type"] == null) 343 xe1.SetAttribute("eye_type", ""); 344 if (xe1.Attributes["nose_type"] == null) 345 xe1.SetAttribute("nose_type", ""); 346 if (xe1.Attributes["mouth_type"] == null) 347 xe1.SetAttribute("mouth_type", ""); 348 349 //添加到<图片标记信息>节点中 350 root.AppendChild(xe1); 351 352 xmldoc.Save("output.xml"); 353 354 } 355 break; 356 case EYE: 357 { 358 if (if_mark_the_picture(root, function_select)) 359 { 360 MessageBox.Show("该图片此类型已经标记过"); 361 return 0; 362 } 363 364 // 查找xml中是否有当前图片信息,有的话不要创建节点,直接添加 365 XmlNodeList nodelist = root.ChildNodes; 366 if (nodelist.Count > 0) 367 { 368 foreach (XmlNode node1 in nodelist) 369 { 370 if (node1.Name == all_picture_name[current_picture_index - 1]) 371 { 372 node1.Attributes["eye_type"].Value = ((Button)sender).Name; 373 374 xmldoc.Save("output.xml"); 375 376 return 1; 377 } 378 } 379 } 380 381 //创建一个<Node>节点 382 XmlElement xe1 = xmldoc.CreateElement(all_picture_name[current_picture_index - 1]); 383 384 //设置该节点 type 属性 385 if (xe1.Attributes["brow_type"] == null) 386 xe1.SetAttribute("brow_type", ""); 387 388 xe1.SetAttribute("eye_type", ((Button)sender).Name); 389 390 if (xe1.Attributes["nose_type"] == null) 391 xe1.SetAttribute("nose_type", ""); 392 if (xe1.Attributes["mouth_type"] == null) 393 xe1.SetAttribute("mouth_type", ""); 394 395 //添加到<图片标记信息>节点中 396 root.AppendChild(xe1); 397 398 xmldoc.Save("output.xml"); 399 400 } 401 break; 402 case NOSE: 403 { 404 if (if_mark_the_picture(root, function_select)) 405 { 406 MessageBox.Show("该图片此类型已经标记过"); 407 return 0; 408 } 409 410 // 查找xml中是否有当前图片信息,有的话不要创建节点,直接添加 411 XmlNodeList nodelist = root.ChildNodes; 412 if (nodelist.Count > 0) 413 { 414 foreach (XmlNode node1 in nodelist) 415 { 416 if (node1.Name == all_picture_name[current_picture_index - 1]) 417 { 418 node1.Attributes["nose_type"].Value = ((Button)sender).Name; 419 420 xmldoc.Save("output.xml"); 421 422 return 1; 423 } 424 } 425 } 426 427 //创建一个<Node>节点 428 XmlElement xe1 = xmldoc.CreateElement(all_picture_name[current_picture_index - 1]); 429 430 //设置该节点 type 属性 431 432 if (xe1.Attributes["brow_type"] == null) 433 xe1.SetAttribute("brow_type", ""); 434 if (xe1.Attributes["eye_type"] == null) 435 xe1.SetAttribute("eye_type", ""); 436 437 xe1.SetAttribute("nose_type", ((Button)sender).Name); 438 439 if (xe1.Attributes["mouth_type"] == null) 440 xe1.SetAttribute("mouth_type", ""); 441 442 //添加到<图片标记信息>节点中 443 root.AppendChild(xe1); 444 445 xmldoc.Save("output.xml"); 446 447 } 448 break; 449 case MOUTH: 450 { 451 if (if_mark_the_picture(root, function_select)) 452 { 453 MessageBox.Show("该图片此类型已经标记过"); 454 return 0; 455 } 456 457 // 查找xml中是否有当前图片信息,有的话不要创建节点,直接添加 458 XmlNodeList nodelist = root.ChildNodes; 459 if (nodelist.Count > 0) 460 { 461 foreach (XmlNode node1 in nodelist) 462 { 463 if (node1.Name == all_picture_name[current_picture_index - 1]) 464 { 465 node1.Attributes["mouth_type"].Value = ((Button)sender).Name; 466 467 xmldoc.Save("output.xml"); 468 469 return 1; 470 } 471 } 472 } 473 474 //创建一个<Node>节点 475 XmlElement xe1 = xmldoc.CreateElement(all_picture_name[current_picture_index - 1]); 476 477 //设置该节点 type 属性 478 479 if (xe1.Attributes["brow_type"] == null) 480 xe1.SetAttribute("brow_type", ""); 481 if (xe1.Attributes["eye_type"] == null) 482 xe1.SetAttribute("eye_type", ""); 483 if (xe1.Attributes["nose_type"] == null) 484 xe1.SetAttribute("nose_type", ""); 485 486 xe1.SetAttribute("mouth_type", ((Button)sender).Name); 487 488 //添加到<图片标记信息>节点中 489 root.AppendChild(xe1); 490 491 xmldoc.Save("output.xml"); 492 493 } 494 break; 495 default: break; 496 } 497 return 1; 498 } 499 #endregion 500 501 #region 此图片该功能类型是否标记过 标记过的返回 true 502 private bool if_mark_the_picture(XmlNode root, int function) 503 { 504 //得到顶层节点列表 505 //XmlNodeList topM = xmld.DocumentElement.ChildNodes; 506 507 XmlNodeList nodelist = root.ChildNodes; 508 if (nodelist.Count > 0) 509 { 510 foreach(XmlNode node1 in nodelist) 511 { 512 if(node1.Name == all_picture_name[current_picture_index - 1]) 513 { 514 switch (function) 515 { 516 case BROW: 517 { 518 if (node1.Attributes["brow_type"].Value != "") 519 return true; 520 } 521 break; 522 case EYE: 523 { 524 if (node1.Attributes["eye_type"].Value != "") 525 return true; 526 } 527 break; 528 case NOSE: 529 { 530 if (node1.Attributes["nose_type"].Value != "") 531 return true; 532 } 533 break; 534 case MOUTH: 535 { 536 if (node1.Attributes["mouth_type"].Value != "") 537 return true; 538 } 539 break; 540 default: break; 541 542 } 543 } 544 } 545 } 546 return false; 547 548 } 549 #endregion 550 551 #region 图片和标记样本 拼接 参数为图片绝对路径 552 private void Join_image(object sender, string picture_name1, string picture_name2) 553 { 554 int total_width = 0; 555 int total_height = 0; 556 int next_width = 0; 557 558 total_width = Image.FromFile(picture_name1).Width + Image.FromFile(picture_name2).Width; 559 // 选高度最高的 560 total_height = Image.FromFile(picture_name1).Height > Image.FromFile(picture_name2).Height ? 561 Image.FromFile(picture_name1).Height : Image.FromFile(picture_name2).Height; 562 563 next_width = Image.FromFile(picture_name1).Width; 564 565 Bitmap new_image = new Bitmap(total_width, total_height); 566 Graphics graph = Graphics.FromImage(new_image); 567 //初始化这个大图 568 graph.DrawImage(new_image, total_width, total_height); 569 570 graph.DrawImage(Image.FromFile(picture_name1), 0, 0, Image.FromFile(picture_name1).Width, Image.FromFile(picture_name1).Height); 571 graph.DrawImage(Image.FromFile(picture_name2), next_width, 0, Image.FromFile(picture_name2).Width, Image.FromFile(picture_name2).Height); 572 573 if (!Directory.Exists("join_image")) 574 { 575 Directory.CreateDirectory("join_image"); 576 } 577 578 string new_image_name = "join_image\\" + picture_name1.Substring( (picture_name1.Length - 579 (picture_name1.Length - current_picture_path.Length)), picture_name1.Length - current_picture_path.Length) + 580 picture_name2.Substring( (picture_name2.Length - 581 (picture_name2.Length - current_type_picture_path.Length)), (picture_name2.Length - current_type_picture_path.Length)); 582 // 保存拼接的图片 583 new_image.Save(new_image_name); 584 585 // 同时保存拼接图片绝对路径 586 join_image_list_path.Add(new_image_name); 587 join_image_list_name.Add(((Button)sender).Name); 588 589 } 590 #endregion 591 592 #region 在按钮上显示拼接后图片 593 private void Show_join_image_in_button() 594 { 595 if (join_image_list_path.Count <= 0) 596 return; 597 598 else if (join_image_list_path.Count < 4) 599 { 600 int index = 0; 601 for (int i = join_image_list_path.Count - 1; i >= 0; i--) 602 { 603 show_join_image_button[index++].BackgroundImage = Image.FromFile(join_image_list_path[i]); 604 605 } 606 } 607 else 608 { 609 int index = 0; 610 for (int i = join_image_list_path.Count - 1; i >= join_image_list_path.Count - 4; i--) 611 { 612 show_join_image_button[index++].BackgroundImage = Image.FromFile(join_image_list_path[i]); 613 614 } 615 616 } 617 618 } 619 #endregion 620 621 #region 选择某张最近标记的图片重新标记 622 private void join_image_button_Click(object sender, EventArgs e) 623 { 624 625 626 627 628 629 } 630 #endregion 631 632 #region 设置图片路径 633 private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) 634 { 635 current_picture_path = ""; 636 all_picture_path.Clear(); 637 all_picture_name.Clear(); 638 639 FolderBrowserDialog FolderBrowserDialog1 = new FolderBrowserDialog(); 640 FolderBrowserDialog1.Description = "请选择图片路径:"; 641 642 if (FolderBrowserDialog1.ShowDialog() == DialogResult.OK) 643 { 644 current_picture_path = FolderBrowserDialog1.SelectedPath; 645 646 DirectoryInfo TheFolder = new DirectoryInfo(current_picture_path); 647 List<string> all = new List<string>(); 648 649 foreach (FileInfo NextFile in TheFolder.GetFiles("*.jpg")) 650 { 651 all.Add(NextFile.Name); 652 653 } 654 foreach (FileInfo NextFile in TheFolder.GetFiles("*.bmp")) 655 { 656 all.Add(NextFile.Name); 657 658 } 659 foreach (FileInfo NextFile in TheFolder.GetFiles("*.png")) 660 { 661 all.Add(NextFile.Name); 662 663 } 664 665 if(all.Count > 0) 666 { 667 for (int i = 0; i < all.Count; i++) 668 { 669 all_picture_path.Add(current_picture_path + @"\" + all[i]); 670 all_picture_name.Add(all[i]); 671 } 672 673 current_picture_index = 1; 674 675 // 显示图片 676 pictureBox1.Load(all_picture_path[current_picture_index - 1]); 677 678 Using_select_picture_button(true); 679 680 } 681 else 682 { 683 MessageBox.Show("此路径下无图片,重新设置"); 684 } 685 686 } 687 else 688 { 689 return; 690 } 691 } 692 #endregion 693 694 #region 上一张或下一张图片 695 private void buttonLeft_Click(object sender, EventArgs e) 696 { 697 698 if (current_picture_index > 1) 699 { 700 --current_picture_index; 701 } 702 else 703 current_picture_index = all_picture_path.Count; 704 705 pictureBox1.Load(all_picture_path[current_picture_index - 1]); 706 707 switch (function_select) 708 { 709 case BROW: 710 { 711 label1.Text = "正在 标记眉毛...第 " + current_picture_index.ToString() + " 张图片"; 712 } 713 break; 714 case EYE: 715 { 716 label1.Text = "正在 标记眼睛...第 " + current_picture_index.ToString() + " 张图片"; 717 } 718 break; 719 case NOSE: 720 { 721 label1.Text = "正在 标记鼻子...第 " + current_picture_index.ToString() + " 张图片"; 722 } 723 break; 724 case MOUTH: 725 { 726 label1.Text = "正在 标记嘴巴...第 " + current_picture_index.ToString() + " 张图片"; 727 } 728 break; 729 default: 730 label1.Text = " 第 " + current_picture_index.ToString() + " 张图片"; 731 break; 732 } 733 734 } 735 736 private void buttonRight_Click(object sender, EventArgs e) 737 { 738 739 if (current_picture_index < all_picture_path.Count ) 740 { 741 ++current_picture_index; 742 } 743 else 744 current_picture_index = 1; 745 746 pictureBox1.Load(all_picture_path[current_picture_index - 1]); 747 748 switch(function_select) 749 { 750 case BROW: 751 { 752 label1.Text = "正在 标记眉毛...第 " + current_picture_index.ToString() + " 张图片"; 753 } 754 break; 755 case EYE: 756 { 757 label1.Text = "正在 标记眼睛...第 " + current_picture_index.ToString() + " 张图片"; 758 } 759 break; 760 case NOSE: 761 { 762 label1.Text = "正在 标记鼻子...第 " + current_picture_index.ToString() + " 张图片"; 763 } 764 break; 765 case MOUTH: 766 { 767 label1.Text = "正在 标记嘴巴...第 " + current_picture_index.ToString() + " 张图片"; 768 } 769 break; 770 default: 771 label1.Text = " 第 " + current_picture_index.ToString() + " 张图片"; 772 break; 773 } 774 775 } 776 #endregion 777 778 #region 下一张图片 779 private void Next_picture() 780 { 781 if (current_picture_index < all_picture_path.Count ) 782 { 783 ++current_picture_index; 784 } 785 else 786 current_picture_index = 1; 787 788 pictureBox1.Load(all_picture_path[current_picture_index - 1]); 789 790 switch(function_select) 791 { 792 case BROW: 793 { 794 label1.Text = "正在 标记眉毛...第 " + current_picture_index.ToString() + " 张图片"; 795 } 796 break; 797 case EYE: 798 { 799 label1.Text = "正在 标记眼睛...第 " + current_picture_index.ToString() + " 张图片"; 800 } 801 break; 802 case NOSE: 803 { 804 label1.Text = "正在 标记鼻子...第 " + current_picture_index.ToString() + " 张图片"; 805 } 806 break; 807 case MOUTH: 808 { 809 label1.Text = "正在 标记嘴巴...第 " + current_picture_index.ToString() + " 张图片"; 810 } 811 break; 812 default: break; 813 } 814 815 } 816 #endregion 817 818 819 #region 标记功能选择 820 private void 标记眉毛ToolStripMenuItem_Click(object sender, EventArgs e) 821 { 822 function_select = BROW; 823 824 if (all_picture_path.Count != 0) 825 { 826 label1.Text = "正在 标记眉毛...第 " + current_picture_index.ToString() + " 张图片"; 827 828 } 829 else 830 { 831 MessageBox.Show("先设置图片路径"); 832 return; 833 } 834 835 Load_xml_set_button(); 836 837 } 838 839 private void 标记眼睛ToolStripMenuItem_Click(object sender, EventArgs e) 840 { 841 842 function_select = EYE; 843 844 if(all_picture_path.Count != 0) 845 { 846 label1.Text = "正在 标记眼睛...第 " + current_picture_index.ToString() + " 张图片"; 847 848 } 849 else 850 { 851 MessageBox.Show("先设置图片路径"); 852 return; 853 } 854 855 Load_xml_set_button(); 856 } 857 858 private void 标记鼻子ToolStripMenuItem_Click(object sender, EventArgs e) 859 { 860 function_select = NOSE; 861 862 if (all_picture_path.Count != 0) 863 { 864 label1.Text = "正在 标记鼻子...第 " + current_picture_index.ToString() + " 张图片"; 865 866 } 867 else 868 { 869 MessageBox.Show("先设置图片路径"); 870 return; 871 } 872 873 Load_xml_set_button(); 874 } 875 876 private void 标记嘴巴ToolStripMenuItem_Click(object sender, EventArgs e) 877 { 878 function_select = MOUTH; 879 880 if (all_picture_path.Count != 0) 881 { 882 label1.Text = "正在 标记嘴巴...第 " + current_picture_index.ToString() + " 张图片"; 883 884 } 885 else 886 { 887 MessageBox.Show("先设置图片路径"); 888 return; 889 } 890 891 Load_xml_set_button(); 892 } 893 #endregion 894 895 #region 是否使图片选择按钮不可见 896 private void Using_select_picture_button(bool if_or_not) 897 { 898 if(if_or_not == true) 899 { 900 buttonLeft.Visible = true; 901 buttonRight.Visible = true; 902 } 903 else 904 { 905 buttonLeft.Visible = false; 906 buttonRight.Visible = false; 907 } 908 909 } 910 #endregion 911 912 #region 选择一种类型后,使该按钮禁用,使其它类型按钮不可见 913 private void Select_one_type_button(object sender) 914 { 915 for(int i=0;i < xml_node_num; i++) 916 { 917 if(type_button[i].Name == ((Button)sender).Name) 918 { 919 type_button[i].Enabled = false; 920 921 } 922 else 923 { 924 type_button[i].Visible = false; 925 } 926 } 927 928 } 929 #endregion 930 931 #region 使所有类型按钮可用可见 932 private void All_type_button_ok() 933 { 934 if (xml_node_num != 0) 935 { 936 for (int i = 0; i < xml_node_num; i++) 937 { 938 type_button[i].Visible = true; 939 type_button[i].Enabled = true; 940 } 941 } 942 else 943 return; 944 945 } 946 #endregion 947 948 949 private void Form1_Load(object sender, EventArgs e) 950 { 951 auto_size_form.Init_control_size(this); 952 } 953 954 private void Form1_SizeChanged(object sender, EventArgs e) 955 { 956 auto_size_form.Auto_control_size(this); 957 958 if(xml_node_num !=0) 959 pictureBox1.Load(all_picture_path[current_picture_index - 1]); 960 961 } 962 963 #region 快捷键按下处理消息 964 private void Form1_KeyDown(object sender, KeyEventArgs e) 965 { 966 if (xml_node_num > 0) 967 { 968 for (int i = 0; i < xml_node_num; i++) 969 { 970 if (e.KeyCode == key_type[i]) 971 { 972 type_button_Click(type_button[i], EventArgs.Empty); 973 } 974 975 } 976 977 } 978 //else 979 // MessageBox.Show("先加载 xml 文件"); 980 } 981 #endregion 982 983 private void 恢复默认设置ToolStripMenuItem_Click(object sender, EventArgs e) 984 { 985 key_type[0] = Keys.NumPad7; 986 key_type[1] = Keys.NumPad8; 987 key_type[2] = Keys.NumPad9; 988 key_type[3] = Keys.NumPad4; 989 key_type[4] = Keys.NumPad5; 990 key_type[5] = Keys.NumPad6; 991 key_type[6] = Keys.NumPad1; 992 key_type[7] = Keys.NumPad2; 993 key_type[8] = Keys.NumPad3; 994 } 995 996 private void 自定义ToolStripMenuItem_Click(object sender, EventArgs e) 997 { 998 Form f2 = new Form2Hotkeys(); 999 f2.ShowDialog(); 1000 } 1001 1002 } 1003 1004 }
浙公网安备 33010602011771号