首先在工程添加对System.Drawing的引用
创建以下方法:
public static ImageSource GetIcon(string fileName)
{
System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(fileName);
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
icon.Handle,
new Int32Rect(,,icon.Width, icon.Height),
BitmapSizeOptions.FromEmptyOptions());
}
在WPF窗体添加一个Image控件
就可以调用了:
this.image1.Source=GetIcon("C:\\test.exe");
转自:http://blog.csdn.net/soft2buy/article/details/6979351