我能否以某种方式使用我操作系统中的文件类型图像并将它们显示在我的应用程序中?
最佳答案
如果你知道你想要的文件的文件名,你可以使用 ExtractAssociatedIcon
为此目的而发挥作用。例如
Icon ico = Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe");
不过这个方法有一个问题。根据其文档,
When ExtractAssociatedIcon is used with bitmaps, a thumbnail image may be returned instead of an icon if the system that is running the application has a registry setting that causes bitmap files to be shown as thumbnail images.
我发现的另一件事是这种方法只能提取 32x32 像素的图标。
参见 System.Drawing.Icon.ExtractAssociatedIcon (MSDN)有关如何使用此方法的更多信息。
要获得更强大的图标提取器,我建议您查看 OSIcon CodeProject 上的项目。
它允许您使用文件名 或 扩展名获取任何文件的关联图标。
这是执行此操作的示例代码:
OSIcon.WinAPI.Shell32.SHFILEINFO shfi = new Shell32.SHFILEINFO();
Icon icon = OSIcon.IconReader.GetFileIcon(".png", IconReader.IconSize.Large, false, ref shfi);
关于c# - 在 C# .NET 中使用操作系统的文件类型镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5164794/