A WPF button opens a file dialog to open an image and display it in an image control
I want to use another button event to open the image in another app, is this possible?
A WPF button opens a file dialog to open an image and display it in an image control
I want to use another button event to open the image in another app, is this possible?
Try this:
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
byte[] data;
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(imagebox.Source as BitmapImage));
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
encoder.Save(ms);
data = ms.ToArray();
}
if (data != null)
{
string filename = dlg.FileName;
System.IO.File.WriteAllBytes(filename, data);
}
}
If you don't want to use a dialog you could just specify the file name in a string variable:
byte[] data;
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(imagebox.Source as BitmapImage));
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
encoder.Save(ms);
data = ms.ToArray();
}
if (data != null)
{
const string filename = @"c:\test\1.jpg";
System.IO.File.WriteAllBytes(filename, data);
}