源:zhantianyou

【WPF】释放图像资源, [删除时报另一进程占用]

CODE

        private BitmapImage ReturnBitmap(string destFile)
        {
            // Read byte[] from png file
            BinaryReader binReader = new BinaryReader(File.Open(destFile, FileMode.Open));
            FileInfo fileInfo = new FileInfo(destFile);
            byte[] bytes = binReader.ReadBytes((int)fileInfo.Length);
            binReader.Close();

            // Init bitmap
            BitmapImage bitmap = new BitmapImage();
            bitmap.BeginInit();
            bitmap.StreamSource = new MemoryStream(bytes);
            bitmap.EndInit();
            return bitmap;
        }

 

相关文章:

  • 2021-12-20
  • 2021-08-02
  • 2022-03-04
  • 2021-07-30
  • 2022-12-23
  • 2021-07-04
  • 2021-12-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案