Load a BitmapSource and save using the same name in WPF -> IOException

后端 未结 5 801
太阳男子
太阳男子 2020-12-21 00:53

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 can

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-21 01:12

    Add the following line to your loading code:

    image.CacheOption = BitmapCacheOption.OnLoad;
    

    This will load open the file, read it into memory, and close it all during image.EndInit. The default of BitmapCacheOption.Default has the odd behavior of opening the file, reading it into memory, but not yet closing it during image.EndInit.

提交回复
热议问题