I am creating a WPF Desktop application in XAML and C# (.NET 5.0). The idea is to load an image file from disc and change the image format i.e. from JPEG to BMP to save space. Loading the file is easy enough:
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
{
PicBox.Source = new BitmapImage(new Uri(open.FileName));
image.Source = PicBox.Source;
}
catch (System.Exception c) { Console.Write("Exception" +c); }
}
}
but when it comes to saving the image to disc I run into a brick wall. I have tried SaveFileDialog() but this seems more for text files - I have used it successfully in text editors, etc but with image files I cannot get my head round it:
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 (image != null)
{
if (save.ShowDialog() == true)
//what goes here??
}
}
image in both code snippets is a global variable of type Image.
I have tried to search for an answer to this but have had no luck.
