0

Here's a little context:

My C# windows form is trying to save a bitmap image with:

        OutputImage.Image = OutputBitmap;
        string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        if (!(System.IO.Directory.Exists(desktopPath + @"\" + "Cache")))
        {
            System.IO.Directory.CreateDirectory(desktopPath + @"\" + "Cache");
        }

        try
        {
            OutputBitmap.Save(desktopPath + "\\Cache\\" + "ImageName.jpg");
        }
        catch
        {
            Debug("-Darn... file error!-");
        }

Now the problem is I have an elementHost containing some WPF code which is using the same bitmap image file for another process:

BitmapSource Source = new BitmapImage(new Uri(desktopPath + "\\Cache\\" + "ImageName.jpg"));

Now since that the file is being used by the WPF element, is it conclusively impossible to have said image saved?

Thanks!

David
  • 9
  • 2
  • You question is hard to understand. If you link file by read-only, you can still edit it on drive, thus mean save – Markiian Benovskyi Jan 24 '18 at 11:20
  • 2
    Although the duplicate question is about deleting an image file, the solution is the same. Make sure the BitmapImage releases the underlying file, either by setting BitmapCacheOption.OnLoad, or by loading it from a FileStream. – Clemens Jan 24 '18 at 11:20
  • Hallelujah! Thanks everyone, it worked perfectly! – David Jan 24 '18 at 11:32

0 Answers0