Created
March 31, 2014 08:00
-
-
Save IamSilviu/9887405 to your computer and use it in GitHub Desktop.
C# Save and Load Image from Database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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