Skip to content

Instantly share code, notes, and snippets.

@IamSilviu
Created March 31, 2014 08:00
Show Gist options
  • Save IamSilviu/9887405 to your computer and use it in GitHub Desktop.
Save IamSilviu/9887405 to your computer and use it in GitHub Desktop.
C# Save and Load Image from Database
private void btnLoad_Click(object sender, RoutedEventArgs e)
{
// Display select file dialog
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)
{
// Get file stream
System.IO.Stream stream = System.IO.File.Open(op.FileName, System.IO.FileMode.Open);
// usage
// Display in wpf image control
BitmapImage imgsrc = new BitmapImage();
imgsrc.BeginInit();
imgsrc.StreamSource = stream;
imgsrc.EndInit();
imgPhoto.Source = imgsrc;
// Save to database
// param-->stream
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment