ImageList:32位图像质量下降

byt*_*e77 6 c# graphics imagelist winforms

我使用ImageListTreeViewListView.我首先将图像质量设置为32位,然后添加半透明图像.质量看起来不错,但在编写,编译和执行应用程序几分钟后,质量看起来很糟糕.

看截图: 在此输入图像描述

使用过的属性

ColorDepth: Depth32Bit
ImageSize: 16; 16
TransparentColor: Transparent
Run Code Online (Sandbox Code Playgroud)

像素背后有黑色像素,半透明但不完全透明.

重新添加所有图像会恢复原始质量,但几分钟后,它就会显示在屏幕截图的右侧.

Woo*_*man 8

当图像存储为ImageStream(VS Designer的默认行为)时,看起来像alpha通道数据丢失.因此,如果您可以停止使用Designer设置图像ImageList,则可以使用半透明图像ColorDepth.Depth32Bit.它非常不方便但它有效.

因此,您可以将图像放到Resources.resx文件中,并将它们添加到代码中的适当位置.例如在你的构造函数UserControl/ Form,调用后,InitializeComponent()通过这样的代码:

  _imageList.Images.Add(Resources.Image32);
  _imageList.Images.SetKeyName(0, "Image32");
  _myButton.Image = 0;
Run Code Online (Sandbox Code Playgroud)

(此信息可在评论中找到回复标记的答案,我已添加此作为答案,因此很难错过另一个可用选项)