In a WPF application, I need to save a Bitmap to disk and than after some changes I try to delete the saved file and save again the modified image.
The problem is once saved, the bitmap doesn't release the file and throws an exception when I try to delete it.
//Gets a bitmap from DevDept.EyeShot model via Scene.RenderToBitmap() and save it to disk
using (var bmpRight = Scene.RenderToBitmap(new System.Drawing.Size(100, 100)))
{
bmpRight.Save(rightPath.Replace(".stl", ".jpg"));
}
Than the user modifies the 3D model and tries to save again with the same name. (Because it is associated to an appointment).
When I try to delete it
if (System.IO.File.Exists(rightPath.Replace(".stl", ".jpg")))
System.IO.File.Delete(rightPath.Replace(".stl", ".jpg"));
I throws an error :
The process cannot access the file because it is in use by another process.
If I do the same thing without Scene2.RenderToBitmap() method of the 3D plateforme, it doesn't produce any error. But, how can it be ? There is no relation between the physical file and the plateforme!
Any idea pleae ?