private void Load_Click(object sender, RoutedEventArgs e) { try { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.Title = "Select a picture"; dlg.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" + "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" + "Portable Network Graphic (*.png)|*.png"; dlg.ShowDialog(); FileStream fs = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read); data = new byte[fs.Length]; fs.Read(data, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); ImageSourceConverter imgs = new ImageSourceConverter(); EmpPicture.SetValue(System.Windows.Controls.Image.SourceProperty, imgs. ConvertFromString(dlg.FileName.ToString())); } catch { } }
private void Load_Click(object sender, RoutedEventArgs e) { try { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.Title = "Select a picture"; dlg.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" + "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" + "Portable Network Graphic (*.png)|*.png"; dlg.ShowDialog(); FileStream fs = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read); data = new byte[fs.Length]; fs.Read(data, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); ImageSourceConverter imgs = new ImageSourceConverter(); EmpPicture.SetValue(System.Windows.Controls.Image.SourceProperty, imgs. ConvertFromString(dlg.FileName.ToString())); } catch { } //OpenFileDialog op = new OpenFileDialog(); //op.Title = "Select a picture"; //op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" + // "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" + // "Portable Network Graphic (*.png)|*.png"; //if (op.ShowDialog() == true) //{ // EmpPicture.Source = new BitmapImage(new Uri(op.FileName)); // //Initialize a file stream to read the image file // FileStream fs = new FileStream(op.FileName, FileMode.Open, FileAccess.Read); // //Initialize a byte array with size of stream // byte[] imgByteArr = new byte[fs.Length]; // //Read data from the file stream and put into the byte array // fs.Read(imgByteArr, 0, Convert.ToInt32(fs.Length)); // //MessageBox.Show(imgByteArr.ToString()); // fileUpload = imgByteArr; // //file upload save as byte // string attchment = Regex.Replace(System.IO.Path.GetFileName(op.FileName), @"\s", string.Empty); // Picture_Filename = attchment; // name = System.IO.Path.GetFileName(Picture_Filename); // sourceFile = System.IO.Path.Combine(op.FileName); // destFile = System.IO.Path.Combine(@"\\skpi-wpcs\c$\SKPI_System_Files\HRiS\", Picture_Filename); //} }