首先,有多种尺寸的图像,其中一些比其他更容易获得。如果您想要“标准”尺寸的(我相信是32x32)并且可以使用WPF(引用PresentationCore),这是一个很好的方法:
public System.Windows.Media.ImageSource Icon
{
get
{
if (icon == null && System.IO.File.Exists(Command))
{
using (System.Drawing.Icon sysicon = System.Drawing.Icon.ExtractAssociatedIcon(Command))
{
// This new call in WPF finally allows us to read/display 32bit Windows file icons!
icon = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
sysicon.Handle,
System.Windows.Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
}
}
return icon;
}
}