private void InputImage_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { ProgressPanel.Visible = true; ProgressPanel.BringToFront(); Enabled = false; try { _srcPath = openFileDialog1.FileName; FiltersList.SelectedIndex = 0; _currentlySelectedTmpFilePath = string.Empty; _currentlySelectedFilterEnum = null; _tmpImgFilePathPattern = Path.GetTempPath() + "\\" + Guid.NewGuid().ToString(); try { InputImage.Image = null; InputImage.Load(_srcPath); ImageInfo imageInfo = new ImageInfo(_srcPath); imageInfo.Start(); while (imageInfo.Running) { Application.DoEvents(); Thread.Sleep(50); } FileInfoEdit.Text = imageInfo.FileInfoText; } catch (Exception exception) { Console.WriteLine(exception); throw; } } finally { ProgressPanel.Visible = false; Enabled = true; } } }
public bool LoadImage(string filePath) { bool reSuccess = false; try { InputImage.Load(filePath); reSuccess = true; } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } return(reSuccess); }
private void FiltersList_SelectedIndexChanged(object sender, EventArgs e) { int selectedIndex = FiltersList.SelectedIndex; if (selectedIndex == 0) { if (File.Exists(_srcPath)) { InputImage.Load(_srcPath); _currentlySelectedTmpFilePath = _srcPath; _currentlySelectedFilterEnum = null; } } else { selectedIndex = selectedIndex - 1; FilterEnum filterEnum = (FilterEnum)selectedIndex; string tmpFilteredImgPath = _tmpImgFilePathPattern + "_" + filterEnum.ToString() + Path.GetExtension(_srcPath); if (File.Exists(tmpFilteredImgPath)) { InputImage.Load(tmpFilteredImgPath); _currentlySelectedFilterEnum = filterEnum; _currentlySelectedTmpFilePath = tmpFilteredImgPath; } else { if (File.Exists(_srcPath)) { ProgressPanel.Location = new Point(Width / 2 - (ProgressPanel.Width / 2), (Height / 2) - (ProgressPanel.Height / 2)); ProgressPanel.Visible = true; ProgressPanel.BringToFront(); Enabled = false; try { string result; switch (filterEnum) { case FilterEnum.Nashville: result = ApplyNashville(_srcPath, tmpFilteredImgPath); break; case FilterEnum.Clarendon: result = ApplyClarendon(_srcPath, tmpFilteredImgPath); break; case FilterEnum.Moon: result = ApplyMoon(_srcPath, tmpFilteredImgPath); break; case FilterEnum.Toaster: result = ApplyToaster(_srcPath, tmpFilteredImgPath); break; case FilterEnum.XPro2: result = ApplyXPro2(_srcPath, tmpFilteredImgPath); break; default: throw new ArgumentOutOfRangeException(); } if (string.IsNullOrEmpty(result)) { if (File.Exists(tmpFilteredImgPath)) { _tmpFilesToClear.Add(tmpFilteredImgPath); InputImage.Load(tmpFilteredImgPath); _currentlySelectedTmpFilePath = tmpFilteredImgPath; _currentlySelectedFilterEnum = filterEnum; } } else { MessageBox.Show(result, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } finally { ProgressPanel.Visible = false; Enabled = true; } } else { MessageBox.Show("Can't find input file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }