首先在工程添加对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(0,0,icon.Width, icon.Height), BitmapSizeOptions.FromEmptyOptions()); }
在WPF窗体添加一个Image控件
就可以调用了:
this.image1.Source=GetIcon("C:\\test.exe");
转自:http://blog.csdn.net/soft2buy/article/details/6979351
时间: 2024-11-15 04:12:58