When I try to save a BitmapSource that was downloaded earlier, a message appears System.IO.IOExceptionsaying that another process is accessing this file and the file stream does not open.
If I save only the download earlier, everything works fine.
Download Code:
BitmapImage image = new BitmapImage();
image.BeginInit();
image.UriSource = uri;
if (decodePixelWidth > 0)
image.DecodePixelWidth = decodePixelWidth;
image.EndInit();
save code:
using (FileStream fileStream = new FileStream(Directory + "\\" + FileName + ".jpg", FileMode.Create))
{
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create((BitmapImage)image));
encoder.QualityLevel = 100;
encoder.Save(fileStream);
}
It seems that after downloading the image data, the file is still locked, it can never be overwritten while the application that opened it is still running. Any ideas how to solve this? Thanks so much for any solutions.
source
share