private void picShow_MouseUp(object sender, MouseEventArgs e) { if (isDrag == true) { isDrag = false; int x1, y1, x2, y2; Image source = Image.FromFile(xmlInfo.ImgFile.FullName); ImageProcess.InOrder(startPoint, e.Location, out x1, out y1, out x2, out y2, source); var p1 = new Point(x1, y1); var p2 = new Point(x2, y2); if (ImageProcess.isRectangle(p1, p2)) { p1 = ImageProcess.ResizedToSource(startPoint, source.Size, picShow.Image.Size); p2 = ImageProcess.ResizedToSource(e.Location, source.Size, picShow.Image.Size); FormClass formClass = new FormClass(ImageProcess.CropRectangle(p1, p2, source), Control.MousePosition); formClass.ShowDialog(); if (formClass.result != -1) { ImageProcess.InOrder(p1, p2, out x1, out y1, out x2, out y2, source); MyObject myObject = new MyObject(formClass.result, x1, y1, x2, y2); xmlInfo.AddObject(myObject); tempBitmap = ImageProcess.DrawRectangle(startPoint, e.Location, tempBitmap, true, 2, myObject.Color); UpdateObjectList(); } } picShow.Image = tempBitmap; GC.Collect(); } }
private void initImageFileList() { if (ConfigFile.ExistCropImage) { int cropImageCount = 0; ImgFileList = new List <FileInfo>(); ImagePairList = new List <ImagePair>(); var allImageFile = ConfigFile.WorkDirectory.EnumerateFiles("*", SearchOption.TopDirectoryOnly).Where(s => GlobalSettings.SupportExtension.Contains(s.Extension.ToLower())); foreach (var file in allImageFile) { if (file.Name.StartsWith(ConfigFile.CropImagePrefix) && file.Name.EndsWith(ConfigFile.CropImageSuffix + file.Extension)) { cropImageCount++; var cropImage = file; string imageName = cropImage.Name.Substring(ConfigFile.CropImagePrefix.Length, cropImage.Name.Length - (ConfigFile.CropImagePrefix + ConfigFile.CropImageSuffix + file.Extension).Length); var imageFile = allImageFile.Where(s => s.Name.Substring(0, s.Name.Length - s.Extension.Length).Equals(imageName)); switch (imageFile.Count()) { case 1: ImagePairList.Add(new ImagePair(imageFile.First(), cropImage)); ImgFileList.Add(imageFile.First()); break; case 0: MessageBox.Show("Can not find the image corresponding to " + cropImage.Name, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; default: MessageBox.Show("Find more than one images corresponding to " + cropImage.Name, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } } } if (ConfigFile.Classes.Count() == 2) { DialogResult dialogResult = MessageBox.Show("Find " + cropImageCount.ToString() + " crop image and " + ImagePairList.Count() + " pairs.\nWould you like to process auto generate?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogResult == DialogResult.Yes) { foreach (var imagepair in ImagePairList) { XMLInfo xmlInfo = new XMLInfo(imagepair.Image); try { var targetList = ImageProcess.TargetObject((Bitmap)Image.FromFile(imagepair.CropImage.FullName)); var nonTargetList = ImageProcess.NonTargetObject((Bitmap)Image.FromFile(imagepair.CropImage.FullName), targetList, 4); foreach (var tar in targetList) { xmlInfo.AddObject(tar); } foreach (var nontar in nonTargetList) { xmlInfo.AddObject(nontar); } xmlInfo.SaveToFile(); } catch (Exception) { MessageBox.Show("Happened unknown error during the process of " + imagepair.Image.Name, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } } else { ImgFileList = ConfigFile.WorkDirectory.EnumerateFiles("*", SearchOption.TopDirectoryOnly).Where(s => GlobalSettings.SupportExtension.Contains(s.Extension.ToLower())).ToList(); } }