c# - C# 中的 Image.FromStream()

标签 c# wpf image

我在 VS 2010、.Net 4.0 中工作。 在 Windows 窗体应用程序中,这是可以的:

Image img = Image.FromStream(imagePart.GetStream());

但是,在 Wpf 应用程序中,Image 类来自 System.Windows.Controls 并且该类无效,因为它没有 FromStream 方法的定义。 在 Windows 窗体中,Image 类是 System.Drawing.Image。

有什么方法可以在 Wpf 应用程序中使用 FromStream 吗?

最佳答案

在 WPF 中,我相信您会使用 BitmapSource例如BitmapImage - 在后一种情况下,您可以设置 StreamSource属性到适当的流。

编辑:BitmapSource 只是ImageSource 的一个子类.通过创建 Image 使用源控制和设置 Source属性(property)。

关于c# - C# 中的 Image.FromStream(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8028497/

相关文章:

c# - 如何实现 Linq OrderBy 方法?

c# - 如何在单元测试中模拟字符串响应?

c# - 在 ViewModel 中创建 KeyBinding 时添加参数

c# - WebClient DownloadFile 路径中的非法字符

image - 如何在 Docker 的 ubuntu 中安装 JLink?

c# - 使用非托管 dll 从 VBA 到 C# 的唯一移植代码

c# - AutoFac Controller 没有默认构造函数

wpf - 将组合框的 ItemsSource 设置为整数数组?

wpf - DataGrid , TextBox - 绑定(bind)和即时更新

ruby-on-rails - 如何检索网站图标?