简体   繁体   English

ImageList:32位图像质量下降

[英]ImageList: 32-bit Images lose quality

I'm using ImageList for TreeView and ListView . 我正在使用ImageList for TreeViewListView I've first set the image quality to 32 bit and then added images which are semi-transparent. 我首先将图像质量设置为32位,然后添加半透明图像。 The quality looks OK, but after a couple of minutes coding, compiling and executing the application, the quality looks bad. 质量看起来不错,但经过​​几分钟编码,编译和执行应用程序后,质量看起来很糟糕。

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

Used properties 使用过的属性

ColorDepth: Depth32Bit
ImageSize: 16; 16
TransparentColor: Transparent

There are black pixels behind pixels which were semi-transparent but not fully transparent. 像素背后有黑色像素,半透明但不完全透明。

Re-adding all images restores the original quality, but after a couple of minutes, it looks like on the right side of the screenshot. 重新添加所有图像会恢复原始质量,但几分钟后,它就会显示在屏幕截图的右侧。

It looks like alpha channel data is lost when images are stored as ImageStream (default behavior of VS Designer). 当图像存储为ImageStream (VS Designer的默认行为)时,看起来alpha通道数据会丢失。 So if you are ok to stop using Designer to set images in ImageList , you can use semitransparent images up to ColorDepth.Depth32Bit . 因此,如果您可以停止使用Designer在ImageList设置图像,则可以使用半透明图像到ColorDepth.Depth32Bit It is very inconvenient but it works. 它非常不方便但它有效。

So you can put your images to Resources.resx file, and add them in appropriate place in code. 因此,您可以将图像放到Resources.resx文件中,并将它们添加到代码中的适当位置。 For example in constructor of you UserControl / Form , after call to InitializeComponent() by code like this: 例如,在UserControl / Form构造函数中,在通过以下代码调用InitializeComponent()之后:

  _imageList.Images.Add(Resources.Image32);
  _imageList.Images.SetKeyName(0, "Image32");
  _myButton.Image = 0;

(This info is available in comments to response marked answer, I've added this as answer so it would be harder to miss another available option) (此信息可在评论中找到回复标记的答案,我已添加此作为答案,因此很难错过另一个可用选项)

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

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