Load a BitmapSource and save using the same name in WPF -> IOException
When I try to save a BitmapSource that I loaded earlier, a System.IO.IOException is thrown stating another process is accessing that file and the filestream cannot be opened. If I only save whithout loading earlier, everything works fine. The loading code: BitmapImage image = new BitmapImage(); image.BeginInit(); image.UriSource = uri; if (decodePixelWidth > 0) image.DecodePixelWidth = decodePixelWidth; image.EndInit(); the saving code: using (FileStream fileStream = new FileStream(Directory + "\\" + FileName + ".jpg", FileMode.Create)) { JpegBitmapEncoder encoder = new JpegBitmapEncoder();