C#:使用多个图像.ico文件 [英] C#: Using .ico file with multiple images

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

问题描述

我想设置图像在C#中一个TreeView,从包含两个图标的.ico文件:一个32×32的版本和一个16×16的版本。这些图像设置,但NET是选择32×32的版本,和缩放下来(这看起来可怕的),而不是选择现成的16x16的形象。

I'm trying to set the images in a TreeView in C#, from a .ico file containing two icons: a 32x32 version and a 16x16 version. The images are setting, but .Net is choosing the 32x32 version, and scaling it down (which looks terrible) instead of choosing the readily available 16x16 image.

相关code:

ilTree.Images.Add(Properties.Resources.group);
ilTree.Images.Add(Properties.Resources.single);
ilTree.Images.Add(Properties.Resources.db);
treeStored.ImageList = ilTree;

我在哪里去了?

Where am I going wrong?


答:

有两件事情你必须做的就是这个工作。第一,如下面所提到的,是手动指定正确的尺寸,以在图像列表。第二个是,你也可能要指定颜色深度。 MSDN指出:

There are two things you must do to get this to work. The first, as mentioned below, is to manually specify the correct size to the image list. The second is that you will also probably have to specify the color depth. MSDN states that:

在.NET Framework 1.1或更高版本,默认为Depth8Bit。

In the .NET Framework version 1.1 or later, the default is Depth8Bit.

......然而,这并没有从我8位图标删除颜色prevent的ImageList。经仔细检查,我的图标(有三个)分别为:4位,4位,8位。两个4位图标共享调色板,但是8位有不同的功能。总共有图标的257色。尽管只有轻微的溢出,净撞倒它归结为一个单纯的 20 的颜色。

...however, that did not prevent ImageList from removing colors from my 8-bit icon. Upon close inspection, my icons (there were three) were: 4bit, 4bit, 8bit. The two 4 bit icons shared palettes, however the 8bit had a different one. In total, there were 257 colors between the icons. Despite the only slight overflow, .Net knocked it down to a mere 20 colors.

推荐答案

您需要创建一个新的图标对象。有一个重载接受原来的图标对象和大小的构造。我不知道,如果新的Icon对象将共享相同的惠康,但它会吸取正确的。为了安全起见,我建议以确保这两个设置。

You need to create a new Icon object. There is an overload for the constructor that accepts the original Icon object and a size. I don't know if the new Icon object will share the same HIcon, but it will draw properly. To be safe, I would recommend ensuring that both are disposed.

这篇关于C#:使用多个图像.ico文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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