c# - 如何在 WPF 的图像控件中分配 System.Drawing.Image 对象

标签 c# wpf winforms

我正在使用一个返回 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/

相关文章:

c# - 从引用的程序集中读取 .resx 文件名

c# - 如何创建引用多个控件的WPF行为?

.net - 如何从ListView控件的单个项目中删除复选框?

.net - 在 WinForms 中使用自定义 WPF 控件

c# - PopupContainerEdit with XtraTreeList 作为下拉演示

c# - 如何在不使用^的情况下实现XOR?

C# ??结合? : question

c# - 有什么方法可以将 SQL Server *data* 转换为 Entity Framework 对象以用于播种数据吗?

WPF 相对源行为

c# - WPF UI Automation with .NET 4.5 with Prism 和 MVVM with Click Once App 便于非开发人员使用