WPF : how can i use a picture while i'm showing it?
Posted
by
Roy Gavrielov
on Stack Overflow
See other posts from Stack Overflow
or by Roy Gavrielov
Published on 2010-12-30T21:05:16Z
Indexed on
2010/12/31
3:53 UTC
Read the original article
Hit count: 439
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.
© Stack Overflow or respective owner