/// <summary> /// Handle the selected image from list view /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lstB_MouseDoubleClick(object sender, MouseButtonEventArgs e) { var item = (CoreImageModel)((System.Windows.Controls.ListView)sender).SelectedItem; CoreImageModel image = new CoreImageModel(); var splitToGetLabel = item.imagePath.Split('\\'); image.imageLabel = splitToGetLabel[splitToGetLabel.Length - 1]; image = findImage(imagesList, image.imageLabel); if (image != null) { txtImagePreview.Text = image.imageLabel; imageToPreview = image.imagePath; BitmapImage bit = new BitmapImage(); bit.BeginInit(); string fullPath = System.IO.Path.GetFullPath(imageToPreview); bit.UriSource = new Uri(fullPath); bit.EndInit(); imgVe.Source = bit; } else { System.Windows.MessageBox.Show("This Emage does not exist!"); } }
} //end btnBrowse_Click //******************************* Image View Tab **************************************** /// <summary> /// /Helper method to find the selected image in the image list /// </summary> /// <param name="list"></param> /// <param name="label"></param> /// <returns></returns> private CoreImageModel findImage(ObservableCollection <CoreImageModel> list, string label) { CoreImageModel image = new CoreImageModel(); foreach (CoreImageModel im in list) { if (im.imageLabel.Equals(label)) { image = im; break; } } return(image); }
/// <summary> /// Read from csv file and populate the list of images in imagesList /// </summary> /// <param name="path"></param> private void readFromFile(string path) { try { StreamReader reader = new StreamReader(File.OpenRead(path)); string line; while (!reader.EndOfStream) { line = reader.ReadLine(); var linesSplit = line.Split(','); if (!linesSplit[0].Equals("workspace")) { CoreImageModel imageObj = new CoreImageModel(); imageObj.imagePath = linesSplit[linesSplit.Length - 1]; var splitToGetLabel = linesSplit[linesSplit.Length - 1].Split('\\'); imageObj.imageLabel = splitToGetLabel[splitToGetLabel.Length - 1]; string pathToCreateImage = "Images\\" + imageObj.imagePath.Substring(2); imageObj.imagePath = pathToCreateImage; System.Drawing.Image newImage = new Bitmap(imageObj.imagePath, true); imageObj.imageShow = newImage; imagesList.Add(imageObj); } } reader.Close(); } catch (IOException e) { System.Windows.MessageBox.Show(e.Message); } }