我应该如何在 Winforms 应用程序中使用 .ico 文件?

发布于 2024-08-24 00:15:55 字数 669 浏览 4 评论 0原文

我正在开发 WinForms c# 3.0 应用程序。我们的设计师创建了大量包含所有所需艺术作品的 .ico 文件。选择 .ico 是因为很多时候,不同尺寸的多个地方都需要相同的图像。

现在,似乎 .ico 文件在 Visual Studio 中使用确实很烦人。使用这些图像的唯一方法似乎是通过图像列表(并非所有控件都支持)。 与其他资源相比,您不能这样写:

foo.Image = global::RFQHUB.RFQHUBClient.Properties.Resources.foo; //    Cannot implicitly convert type 'System.Drawing.Icon' to 'System.Drawing.Image'  

以下是我正在考虑的选项:

  • 创建所有可能大小的 ImageList,引用主窗口中的所有图标。从其他窗口链接这些ImageList,当我不能直接使用它时,找到一种方法从ImageList导出Image对象;由于 ImageList 包含一个 Draw() 方法,因此这应该是可能的。
  • 转换我在几个 x16.gif ...x48.gif 中获得的所有 x.ico,并通过资源使用它们。

我很想知道是否有人已在 Winform 应用程序中成功使用 .ico 资源。那么,你是如何设置的呢?

I'm developing a WinForms c# 3.0 application. Our designer created quite a lot of .ico files containing all the needed art. The choice of .ico was made because quite often, the same image is needed in several places in different dimensions.

Now, it seems .ico files are really annoying to use in visual studio. The only way to use those images seems to be through images list (which aren't supported by all controls).
Compared to other resources, you can't write this :

foo.Image = global::RFQHUB.RFQHUBClient.Properties.Resources.foo; //    Cannot implicitly convert type 'System.Drawing.Icon' to 'System.Drawing.Image'  

Here are the options I'm considering :

  • create ImageLists of all possible sizes referencing all my icons in my main window. Link these ImageLists from other windows and find a way to export Image objects from the ImageList when I can't use it directly ; since ImageList contains a Draw() method, this should probably be possible.
  • convert all the x.ico I've got in several x16.gif ...x48.gif, and use those through resources.

I'd be interested to know if some people have been successfully using .ico resources in a Winform application. In so, how did you set up things ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两人的回忆 2024-08-31 00:15:55

ICO 并不是一种过时的格式,但也已经很接近了。它对于您的应用程序图标仍然有用,但对于几乎所有其他内容,最好针对您需要的每种尺寸使用 ImageList。从包含网格中布局的多个图像的位图中填充 ImageList 的速度要快得多。

您还希望在位图中使用 Alpha 通道透明度以获得最佳结果,因此将它们作为 .PNG 文件存储在资源中是最好的方法,因为 PNG 支持 Alpha 通道。 ICO 和 GIF 文件仅支持一位透明度 - 每个像素要么完全不透明,要么完全透明。 8 位 Alpha 通道的透明度看起来更好。

如果您可以将您的艺术家送回绘图板,那么您应该这样做,并让他/她使用 Alpha 制作完整的抗锯齿图像。如果不能,那么我建议您编写一个小程序,将所有图标文件转换为适合加载到 ImageList 中的位图。

ICO isn't quite an obsolete format, but it's close. It's still useful for your application icon, but for almost everything else, it's better to use an ImageList for each size that you need. And it's much faster to populate an ImageList from a bitmap that contains multiple images layed out in a grid.

You also want to use an Alpha channel transparency in your bitmaps to get the best result, so storing them as .PNG files in your resources is the best way to go, since PNG supports an alpha channel. ICO and GIF files support only single bit for transparency - every pixel is either fully opaque or fully transparent. An 8 bit alpha channel for transparency looks much nicer.

If you can send your artist back to the drawing board then you should do so, and have him/her do full anti-aliased images with alpha. If you can't, then I suggest that you write a small program to convert all of your icon files into bitmaps suitable for loading into ImageLists.

青丝拂面 2024-08-31 00:15:55

将图像转换为 PNG。观点。无论谁决定首先使用 .ico 文件,都应该私下与他们交谈 - 这个论点没有根据。

Convert the images into PNG. Point. Whoever decided to use .ico files to start with should get talked to in private - the argument holds no ground.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文