.Net ToolStrip 和 ImageList - 图像大小错误
我有一个图标,其中包含尺寸为 16x16、24x24 和 32x32 的 32 位图像。我创建了三个包含三个不同尺寸图像的 ImageList 对象,并根据用户选择的尺寸在 ToolStrip 上分配 ImageList 属性。然而,ToolStrip 对象上显示的图像都是 32x32 图像的缩放版本。例如,我不明白为什么当我创建 16x16 ImageList 时,它没有从图标中提取 16x16 图像。我的代码基本上是这样的:
ImageList m_imageList16 = new ImageList();
m_imageList16.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
m_imageList16.ImageSize = new System.Drawing.Size(16, 16);
m_imageList16.TransparentColor = System.Drawing.Color.Transparent;
// Open is an icon in my resources that contains various sizes of images.
m_imageList16 .Images.Add(global::MyTestApp.Properties.Resources.Open);
// Later when the user selects the 16 size from a menu, I change the toolbar:
m_toolbar.ImageScalingSize = new Size(16, 16);
m_toolbar.ImageList = m_imageList16;
看起来这只是将我的图标中的 32x32 大小的图像缩小到 16x16,而不是使用图标中定义的 16x16 图像。谁能帮忙解决这个问题吗?预先感谢您的任何意见!
- 史蒂夫
I have an icon that contains 32-bit images of sizes 16x16, 24x24, and 32x32. I create three ImageList objects that contain the three different size images, and assign the ImageList property on my ToolStrip given what size the user selects. However the images displayed on the ToolStrip objects are all scaled versions of the 32x32 image. I can't figure out why when I create the 16x16 ImageList, for example, that it doesn't extract the 16x16 image from the icon. My code essentially looks like this:
ImageList m_imageList16 = new ImageList();
m_imageList16.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
m_imageList16.ImageSize = new System.Drawing.Size(16, 16);
m_imageList16.TransparentColor = System.Drawing.Color.Transparent;
// Open is an icon in my resources that contains various sizes of images.
m_imageList16 .Images.Add(global::MyTestApp.Properties.Resources.Open);
// Later when the user selects the 16 size from a menu, I change the toolbar:
m_toolbar.ImageScalingSize = new Size(16, 16);
m_toolbar.ImageList = m_imageList16;
It seems this just takes the 32x32 size image in my icon and scales it down to 16x16, rather than using the 16x16 image defined in the icon. Can anyone help with this? Thanks in advance for any input!
- Steve
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找不到任何证据来支持我的理论,但 ImageList 似乎不知道选择不同大小的图标。我的直觉是它只是将图标转换为位图并存储该数据。
在 MSDN 论坛,我从 MVP 用户 nobugz 那里找到了这个片段:
另外,CSharpKey 的此页面似乎是使用 ImageList 和图标的有用资源。这是摘录:
看起来“言外之意”是,ImageList 仅存储一种尺寸并返回所存储图像的重新采样版本。
编辑
我在CodeProject上找到了另一个参考(Embedding Icons in your VB .NET 应用程序),内容如下:
I can't find any evidence to support my theory, but ImageList appears to not be aware of selecting different size icons. My hunch is that it simply converts icons to bitmaps and stores that data.
At MSDN forums, I found this snippet from MVP user nobugz:
Also, this page from CSharpKey seemed a useful resource working with ImageLists and icons. Here's an excerpt:
It seems to be, "reading between the lines" that the ImageList merely stores one size and returns resampled versions of the image stored.
Edit
I found another reference at CodeProject (Embedding Icons in your VB.NET application) that says this:
我早在 2006 年就提交了这个 bug,微软 bug 人员回应说他们可以重现这个问题,但这不是一个关键问题,他们不会修复它。
我现在使用适当的 png,而不是多尺寸图标。
I filed this bug back in the year 2006, and the Microsoft bug guys responded that they can reproduce the problem, but it is not a critical one, and they are not going to fix it.
I am now using the appropriate pngs instead of multisize icons.