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

源:zhantianyou

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;
        }

 

posted @ 2016-05-20 17:09  oiliu  阅读(1133)  评论(0编辑  收藏  举报