I use this function to load a photo:
private void Load_Photo()
{
BitmapImage bi1 = new BitmapImage();
bi1.BeginInit();
bi1.UriSource = new Uri(photolocation, UriKind.Absolute);
bi1.EndInit();
if (bi1 != null)
{
Image_Data = bi1;
}
}
Then I want to save over the same photo that gives me an error saying: System.IO.IOException 'The proces cannot access the file 'photolocation' because it is being used by another process.
private void Save_Photo_To_JPG()
{
var encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(Image_Data));
using (var filestream = new FileStream(photolocation, FileMode.Create))
encoder.Save(filestream);
}
How can I solve this?