我正在使用一个返回 System.Drawing.Image
对象的 DLL。我在 winform c# 中使用那个 DLL,并且工作正常。现在我在 WPF 中升级我的应用程序,我很困惑如何将这个返回对象 (System.Drawing.Image)
分配给我在 wpf 中的 Image
控件?有帮助吗?
最佳答案
怎么样
// Winforms Image we want to get the WPF Image from...
System.Drawing.Image imgWinForms = WindowsImageFromDLL();
// ImageSource ...
BitmapImage bi = new BitmapImage();
bi.BeginInit();
MemoryStream ms = new MemoryStream();
// Save to a memory stream...
imgWinForms.Save(ms, ImageFormat.Bmp);
// Rewind the stream...
ms.Seek(0, SeekOrigin.Begin);
// Tell the WPF image to use this stream...
bi.StreamSource = ms;
bi.EndInit();
这样你的图像就不会作为文件存储在系统中。
关于c# - 如何在 WPF 的图像控件中分配 System.Drawing.Image 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16384038/