繁体   English   中英

在 ToolStripButton 上使用 ImageList 时图像失真

[英]Distorted images when using ImageList on ToolStripButton

我想将一些图像放入ToolStripButton ,并根据按钮的状态更改图像。

所以我已经将ToolStrip.ImageList设置为我的ImageList并简单地将ToolStripButton.ImageIndex更改为适当的值。

但是,与直接向ToolStripButton.Image属性提供完全相同的图片相比,图标显得扭曲。

在下图中,左侧的图像是来自ImageList的图像,右侧的图像是通过ToolStripButton.Image设置的。 如您所见,左侧的有一些小的奇数像素,在选择按钮时特别明显。

我试过修改TransparencyColorColorDepth但这没有任何区别。 关于我失踪的任何线索?

奇怪的图标

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

你可以把图片放在 Resources 中,用Dictionary替换ImageList吗? 在这种情况下,图片将与原始图片相同。

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 代码在VB.NET但您会明白这一点。

暂无
暂无

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

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