您的位置:首页 > 其它

WPF获取外部EXE图标最简单的方法

2013-07-21 22:38 141 查看
首先在工程添加对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");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: