使用操作系统的文件类型的图像在C#.NET [英] Use the file types image of the operating system in C# .NET

查看:165
本文介绍了使用操作系统的文件类型的图像在C#.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用某种方式的文件类型的图像从我的操作系统,并在我的应用程序中显示它们?

Can I use somehow the filetype images from my operating system and display them in my application?

推荐答案

如果你知道你想要的图标的文件的文件名,则可以使用的 ExtractAssociatedIcon 功能用于这一目的。例如,

If you know the file name of the file whose icon you want, you can use the ExtractAssociatedIcon function for that purpose. e.g.

Icon ico = Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe");

这都是一个收获这种方法虽然。据其文档,

There is a catch to this method though. According to its documentation,

当ExtractAssociatedIcon一起使用位图,缩略图图像可以返回图标而不是如果正在运行应用程序的系统具有这样导致位图文件被显示为缩略图图像的注册表设置。

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.

还有一件事,我发现的是,这种方法仅提取32x32pixel图标。

One other thing I found was that this method only extracts 32x32pixel icons.

请参阅的 System.Drawing.Icon.ExtractAssociatedIcon(MSDN)了解如何使用这个方法。

See System.Drawing.Icon.ExtractAssociatedIcon (MSDN) for more how to use this method.

有关更强大的图标提取器,我建议你看的在$ C $的CProject OSIcon 项目
。 它可以让你使用它的文件名的的扩展得到任何文件的关联图标。
下面是一个示例code做的:

For a more robust icon extractor, I'd suggest you look at the OSIcon project on CodeProject.
It allows you to get the associated icon of any file using its file name or extension.
Here is a sample code for doing that:

OSIcon.WinAPI.Shell32.SHFILEINFO shfi = new Shell32.SHFILEINFO();
Icon icon = OSIcon.IconReader.GetFileIcon(".png", IconReader.IconSize.Large, false, ref shfi);

这是链接到项目: HTTP://www.$c$cproject.com/KB/system/OSIcon.aspx

这篇关于使用操作系统的文件类型的图像在C#.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆