如果我有一个文件的path,有没有办法,我可以得到Windows资源pipe理器中的窗口将显示该文件的图标?
首先,图像有多种尺寸,其中一些比其他的更容易获得。 如果你想要“正常”的大小(我相信32×32),并可以使用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; } }
System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(filePath);