How to release Image from Image Source in WPF

前端 未结 2 1875
温柔的废话
温柔的废话 2020-12-16 14:09

Am loading image like below

XAML



        
2条回答
  •  無奈伤痛
    2020-12-16 14:35

    You should not use that Image directly in your application if you want to delete or move it.

    imgThumbnail.Source = new BitmapImage(new Uri(filePath));
    

    Instead, do this:

    BitmapImage image = new BitmapImage();
    image.BeginInit();
    image.CacheOption = BitmapCacheOption.OnLoad;
    image.UriSource = new Uri(filePath);
    image.EndInit();
    imgThumbnail.Source = image;
    

    For more read this

提交回复
热议问题