我的WPF应用程序中有一个按钮和名为image1的图像。我想从位置图标或文件路径添加图像1的图像源。这是我的代码:
using System.Windows;
using System.Windows.Media.Imaging;
using System.IO;
using System.Drawing;
namespace WpfApplication2
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Icon ico = System.Drawing.Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe");
image1.Source = ico.ToBitmap();
}
}
}
错误提示如下:
无法将类型“System.Drawing.Bitmap”隐式转换为类型“System.Windows.Media.ImageSource”
如何解决这个问题?