BitmapImage 资源释放

来源:互联网 发布:minami氨基酸知乎 编辑:程序博客网 时间:2024/05/16 09:16
最后发现初始化BitmapImage可以通过byte[]进行,于是只能通过将png文件读成byte[],再进行BitmapImage的初始化,就没有问题了


// Read byte[] from png file
BinaryReader binReader = new BinaryReader(File.Open(filePath, FileMode.Open));
FileInfo fileInfo = new FileInfor(filePath);
byte[] bytes = binReader.ReadBytes((int)fileInfo.Length);
binReader.Close();


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

bitmap.EndInit();



image.Dispose();
System.GC.SuppressFinalize(image);


BitmapImage bitmapImage = image.Source as BitmapImage;

  bitmapImage.UriSource = null;

  image.Source = null;


原创粉丝点击