C#中的Image.FromStream()

pet*_*ski 3 c# wpf image

我在VS 2010,.Net 4.0工作.在Windows窗体应用程序中,这没关系:

Image img = Image.FromStream(imagePart.GetStream());
Run Code Online (Sandbox Code Playgroud)

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

有没有办法在Wpf应用程序中使用FromStream?

Jon*_*eet 6

在WPF中我相信你会使用BitmapSource诸如BitmapImage- 在后一种情况下,你可以将StreamSource属性设置为适当的流.

编辑:BitmapSource只是一个子类ImageSource.通过创建Image控件并设置Source属性来使用源.