方法一
private ImageSource ByteArrayToImageSource(byte[] data){System.Drawing.Image image;using (MemoryStream ms = new MemoryStream(data)){image = System.Drawing.Image.FromStream(ms);}var bitmap = new Bitmap(image);return Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());}
方法二
private ImageSource ByteArrayToImageSource(byte[] data){BitmapImage image = new BitmapImage();using (MemoryStream ms = new MemoryStream(data)){ms.Position = 0;image.BeginInit();image.CacheOption = BitmapCacheOption.OnLoad;image.StreamSource = ms;image.EndInit();image.Freeze();}return image;}