private void ImgOpen() { string ImgFilePath = ""; try { var dialog = new OpenFileDialog(); dialog.ValidateNames = false; dialog.CheckFileExists = false; dialog.CheckPathExists = true; dialog.FileName = "default"; dialog.Filter = "All files|*.*|Image files(*.jpg)|*.jpg"; dialog.ShowDialog(); string Path = System.IO.Path.GetFullPath(dialog.FileName); Path = Path.Replace("default", "").Trim(); ImgFilePath = Path; string[] parser = Path.Split('.'); Console.WriteLine(Path); if (parser.Length == 2) { string imgpath = Path; FileList.Add(imgpath); string temp = imgpath; string[] fileparse = temp.Split('\\'); VisibleFileList.Add(fileparse[fileparse.Length - 1]); } else { string[] parse = Path.Split('.'); string[] files = Directory.GetFiles(parse[0]); foreach (string x in files) { FileList.Add(x); string temp = x; string[] fileparse = temp.Split('\\'); VisibleFileList.Add(fileparse[fileparse.Length - 1]); } } } catch (Exception ex) { Console.WriteLine($"An exception occurred from {MethodBase.GetCurrentMethod().Name}"); Console.WriteLine(ex.ToString()); } }
private void SelectImgConvert() { Image target = Image.FromFile(FileList[VisibleFileList.IndexOf(ImgSelect)]); string finaldest = DestPath + "\\" + VisibleFileList[VisibleFileList.IndexOf(ImgSelect)]; Console.WriteLine(finaldest); string[] fileparse = finaldest.Split('.'); Bitmap bmp = new Bitmap(target); if (target != null) { bmp.Save(DestPath + "\\" + fileparse[1] + ".png", System.Drawing.Imaging.ImageFormat.Png); } logViewModel.AddLog(GetType(), VisibleFileList[VisibleFileList.IndexOf(ImgSelect)]); }