Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在WPF';s图像控制_C#_Wpf_Winforms - Fatal编程技术网

C# 如何在WPF';s图像控制

C# 如何在WPF';s图像控制,c#,wpf,winforms,C#,Wpf,Winforms,我正在使用一个DLL,它返回一个System.Drawing.Image对象。我在winform c#中使用了该DLL,工作正常。现在,我正在升级WPF中的应用程序,并弄不清楚如何将此返回对象(System.Drawing.Image)分配给WPF中的Image控件?有什么帮助吗?怎么样 // Winforms Image we want to get the WPF Image from... System.Drawing.Image imgWinForms = WindowsImageFr

我正在使用一个DLL,它返回一个
System.Drawing.Image
对象。我在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();
这样,图像将不会作为文件存储在系统中。

如何

// 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();

这样,图像将不会作为文件存储在系统中。

system.Drawing.image在中不可用WPF@UzmaGelani:读取此System.Drawing.Image在中不可用WPF@UzmaGelani:读这个