You can do for example =>
BitmapImage bi = null; // Global
private void LoadBtn_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Title = "Open Picture";
open.Multiselect = false;
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == true)
{
try
{
bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(open.FileName, UriKind.RelativeOrAbsolute);
bi.EndInit();
PicBox.Source = bi;
}
catch (System.Exception c) { Console.Write("Exception" + c); }
}
}
private void SaveBtn_Click(object sender, RoutedEventArgs e)
{
SaveFileDialog save = new SaveFileDialog();
save.Title = "Save picture as ";
save.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (bi != null)
{
if (save.ShowDialog() == true)
{
JpegBitmapEncoder jpg = new JpegBitmapEncoder();
jpg.Frames.Add(BitmapFrame.Create(bi));
using (Stream stm = File.Create(save.FileName))
{
jpg.Save(stm);
}
}
}
}