简体   繁体   English

在 ToolStripButton 上使用 ImageList 时图像失真

[英]Distorted images when using ImageList on ToolStripButton

I want to put some images into a ToolStripButton , and have the images change depending on the state of the button.我想将一些图像放入ToolStripButton ,并根据按钮的状态更改图像。

So I've set the .ImageList of the ToolStrip to be my ImageList and simply change the ToolStripButton.ImageIndex to the appropriate value.所以我已经将ToolStrip.ImageList设置为我的ImageList并简单地将ToolStripButton.ImageIndex更改为适当的值。

However, the icons appear distorted in comparison to providing exactly the same picture directly to the ToolStripButton.Image property.但是,与直接向ToolStripButton.Image属性提供完全相同的图片相比,图标显得扭曲。

In the picture below the image on the left hand side is the one from the ImageList , the one on the right is being set through ToolStripButton.Image .在下图中,左侧的图像是来自ImageList的图像,右侧的图像是通过ToolStripButton.Image设置的。 As you can see, the one on the left has some small odd pixels, specially visible when the button is selected.如您所见,左侧的有一些小的奇数像素,在选择按钮时特别明显。

I've tried modifying the TransparencyColor and ColorDepth but that's not made any difference.我试过修改TransparencyColorColorDepth但这没有任何区别。 Any clues as to what I'm missing?关于我失踪的任何线索?

奇怪的图标

尝试将AutoSize设置为false并将ImageScaling设置为ToolStripItemImageScaling.None

You can put pictures in Resources and replace ImageList with Dictionary ?你可以把图片放在 Resources 中,用Dictionary替换ImageList吗? In this case, pictures will be equal to the original.在这种情况下,图片将与原始图片相同。

Dim dictPictures As New Dictionary(Of String, Bitmap)
Dim runTimeResourceSet As Object
Dim dictEntry As DictionaryEntry
runTimeResourceSet = My.Resources.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, True, True)
For Each dictEntry In runTimeResourceSet
    If (dictEntry.Value.GetType() Is GetType(Bitmap)) Then
        If Not dictPictures.ContainsKey(dictEntry.Key & ".png") Then dictPictures.Add(dictEntry.Key & ".png", dictEntry.Value)
    End If
Next

PS Code is in VB.NET but you'll get the point. PS 代码在VB.NET但您会明白这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM