WPF : how can i use a picture while i'm showing it?
- by Roy Gavrielov
hello, i'm trying to do so but the program throws this exception :
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
Additional information: The process cannot access the file 'C:\Users\Roy\documents\visual studio 2010\Projects\Assignment3\Assignment3\bin\Debug\Images\Chrysanthemum.jpg' because it is being used by another process.
is there a way to use it while it's open?
code :
if (imgAddMessage.Source != null)
{
BitmapImage src = (BitmapImage)imgAddMessage.Source;
if (!Directory.Exists("Images"))
{
Directory.CreateDirectory("Images");
}
FileStream stream = new FileStream("Images/" + imageName, FileMode.Create, FileAccess.ReadWrite);
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(src));
encoder.Save(stream);
stream.Close();
}
thanks.