9

I'm using ImageList for TreeView and ListView. I've first set the image quality to 32 bit and then added images which are semi-transparent. The quality looks OK, but after a couple of minutes 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 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.

Ivan Karajas
  • 1,081
  • 8
  • 14
bytecode77
  • 14,163
  • 30
  • 110
  • 141
  • Which version of Visual Studio? I bet it works fine if you load up the image list at runtime. Probably a bug in the VS code that stores/loads the image list state at designtime. – David Heffernan Apr 29 '12 at 14:23
  • It's VS2010 Ultimate. I also first thought about loading them at runtime, but that is not the way it *should* be. Any other ideas? – bytecode77 Apr 29 '12 at 15:03
  • Loading at runtime from a resource is exactly what I would do. Then I can choose a size that matches the font scaling. – David Heffernan Apr 29 '12 at 15:09
  • @bytecode77 Cannot respond in proper thread, because Hans Passant removed his answer. Regarding adding images to imagelist - this is quite weird, take a look: http://stackoverflow.com/questions/28902091/32-bit-images-on-imagelist – Spook Mar 06 '15 at 15:56

1 Answers1

10

It looks like alpha channel data is lost when images are stored as ImageStream (default behavior of VS Designer). So if you are ok to stop using Designer to set images in ImageList, you can use semitransparent images up to 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. For example in constructor of you UserControl/Form, after call to InitializeComponent() by code like this:

  _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)

huseyint
  • 14,953
  • 15
  • 56
  • 78
Woodman
  • 1,108
  • 9
  • 11
  • Thank you very much! This is great, I didn't understand why the transparency didn't look good. But, I think, the last line should be `_myButton.ImageIndex = 0;` – Aaron Tuil Jul 31 '22 at 14:15