public void OnCreateNewPersonClicked(object sender, EventArgs e) { if (picSelected) { if (!String.IsNullOrWhiteSpace(_view.NameSurname) && DateTime.Compare(_view.BirthDate, _view.MissingDate) <= 0) { picSelected = false; // to do: make another class and method for photos validation string directory = _view.NameSurname; directory = directory.Replace(" ", "_"); /*if (!File.Exists(Application.StartupPath + "/data/" + directory + "/rep.bmp")) * ImageHandler.SaveRepresentativePic(tempImage.ToBitmap(), directory);*/ int viablePicsCount = 0; foreach (string filename in picFilenames) { tempImage = new Image <Bgr, byte>(filename); var face = PersonRecognizer.Instance.GetFaceFromImage(tempImage); if (face != null) { Image <Gray, byte> grayFace = PersonRecognizer.Instance.ConvertFaceToGray(face); string faceFile = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + Settings.Default.DataFolderPath + Settings.Default.ImagesFolderPath + directory + "/"; if (!Directory.Exists(faceFile)) { Directory.CreateDirectory(faceFile); } int picNumber = 1; while (File.Exists(faceFile + picNumber + ".bmp")) { picNumber++; } grayFace.Save(faceFile + picNumber + ".bmp"); viablePicsCount++; } } if (viablePicsCount > 0) { _model.Add(_view.NameSurname, _view.BirthDate.ToString(), _view.MissingDate.ToString(), _view.AdditionalInfo); _view.AddPersonToList(_model.CurrentPerson); _view.ShowMessage(String.Format(Properties.Resources.AddPersonPhotosAddedMsg, _view.NameSurname, viablePicsCount, picFilenames.Count)); _view.PersonImage = Resources.NewPerson; _view.NameSurname = ""; _view.NameSurnameEnabled = true; _view.MissingDate = DateTime.Today; _view.BirthDate = DateTime.Today; _view.AdditionalInfo = ""; } else { _view.ShowMessage(Resources.AddPersonsNoValidPersonsError); } } else { _view.ShowMessage(Resources.AddPersonNotValidInfoError); } } else { _view.ShowMessage(Resources.AddPersonNoPhotosError); } }
public void OnCreateNewPersonClicked(object sender, EventArgs e) { if (picSelected) { if (!String.IsNullOrWhiteSpace(_view.NameSurname) && DateTime.Compare(_view.BirthDate, _view.MissingDate) <= 0) { picSelected = false; // to do: make another class and method for photos validation string directory = _view.NameSurname; directory = directory.Replace(" ", "_"); if (!File.Exists(Application.StartupPath + "/data/" + directory + "/rep.bmp")) { ImageHandler.SaveRepresentativePic(tempImage.ToBitmap(), directory); } int viablePicsCount = 0; foreach (string filename in picFilenames) { tempImage = new Image <Bgr, byte>(filename); if (ImageHandler.GetFaceFromImage(tempImage) != null) { var newFace = ImageHandler.GetFaceFromImage(tempImage); var newGrayFace = newFace.Convert <Gray, Byte>(); ImageHandler.SaveGrayFacetoFile(directory, newGrayFace); viablePicsCount++; } } if (viablePicsCount > 0) { _view.AddPersonToList(_view.NameSurname); _model.Add(_view.NameSurname, _view.BirthDate.ToString(), _view.MissingDate.ToString(), _view.AdditionalInfo); // to do: load/save data doing on start/exit program ImageHandler.WriteDataToFile(FirstPageView.persons); _view.ShowMessage(String.Format(Properties.Resources.AddPersonPhotosAddedMsg, _view.NameSurname, viablePicsCount, picFilenames.Count)); _view.PersonImage = Properties.Resources.NewPerson; _view.NameSurname = ""; _view.NameSurnameEnabled = true; _view.MissingDate = new DateTime(); _view.BirthDate = new DateTime(); _view.AdditionalInfo = ""; } else { _view.ShowMessage(Properties.Resources.AddPersonsNoValidPersonsError); } } else { _view.ShowMessage(Properties.Resources.AddPersonNotValidInfoError); } } else { _view.ShowMessage(Properties.Resources.AddPersonNoPhotosError); } }