Lahiru Mahagamage

Lahiru Mahagamage

  • NA
  • 45
  • 1.3k

How to delete file opened by a Canvas

Jan 12 2018 4:00 AM
hello guys, 
 
 I'm opening a .bmp image created on a folder on a InkCanvas to draw on like below. And when i'm closing it i want the TempFile to be deleted. but when i try to delete it says the file is used by another process. is there anyway to do this? I'm using WPF C#. Please help me out.
 
Thanks  you! :)
 
  1. img = new BitmapImage(new Uri(TempFile, UriKind.Relative));  
  2.   
  3. myImageBrush = new ImageBrush(img);  
  4. myCanvas = new Canvas();  
  5. myCanvas.Width = img.Width;  
  6. myCanvas.Height = img.Height;  
  7. myCanvas.Background = myImageBrush;  
  8.   
  9. cw.ImgPO.Height = img.Height;  
  10. cw.ImgPO.Children.Add(myCanvas);  
 
 

Answers (6)