标签:style blog color io 数据 sp div on log
当WPF的Image控件显示数据库调出的字节数组图像时,会出异常。一般是用了using()或者关闭流就会不显示图像。
Source.Metadata”引发了“System.NotSupportedException”类型的异常
byte[] b = File.ReadAllBytes(Directory.GetCurrentDirectory() + "\\test.jpg"); //using (MemoryStream ms = new MemoryStream(b)) //{ // BitmapImage bm = new BitmapImage(); // bm.BeginInit(); // //long a = ms.Seek(0, SeekOrigin.Begin); // bm.StreamSource = ms; // bm.EndInit(); // image_1.Source = bm; //}
//下边的代码正常,因为去掉了using()
MemoryStream ms = new MemoryStream(b); BitmapImage bm = new BitmapImage(); bm.BeginInit(); //long a = ms.Seek(0, SeekOrigin.Begin); bm.StreamSource = ms; bm.EndInit(); image_1.Source = bm;
Wpf的Image控件显示MemoryStream提供的流图像时抛异常处理方法
标签:style blog color io 数据 sp div on log
原文地址:http://www.cnblogs.com/mytianao/p/4012705.html