ImageList: 32-bit images lose quality

I am using ImageList for TreeView and ListView . First I set the image quality to 32 bits, and then I added images that are translucent. The quality looks fine, but after a few minutes of coding, compiling and executing the application, the quality looks bad.

See screenshot: enter image description here

Used properties

 ColorDepth: Depth32Bit ImageSize: 16; 16 TransparentColor: Transparent 

There are black pixels behind the pixels that were translucent but not completely transparent.

Re-adding all the images restores the original quality, but after a couple of minutes it looks on the right side of the screenshot.

+6
source share
1 answer

It looks like alpha channel data is lost when images are stored as ImageStream (VS Designer default behavior). Therefore, if you can stop using Designer to set images in ImageList , you can use translucent images before ColorDepth.Depth32Bit . This is very inconvenient, but it works.

So, you can put your images in the Resources.resx file and add them to the appropriate place in the code. For example, in the constructor from UserControl / Form after calling InitializeComponent() using code:

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

(This information is available in the comments to the answer, I added this as an answer, so it would be harder to miss another available option)

+8
source

Source: https://habr.com/ru/post/914463/


All Articles