views:

144

answers:

3

Hi

Does anyone have a solution for the color bleeding when using a StateImageList with a Windows Forms TreeView?

Using the same ImageList with assigned to the TreeView's ImageList property, results in correct rendering as can be seen by the following image.

24 bit

The state images are left, normal images are right. All images are sourced from the same ImageList instance.

Update:

I converted the images to 16 color indexed palette. Seems it does not like that either. Its a bit better, but still far from acceptable.

4 bit

A: 

Looks like the images are reduced in bit depth.

Is the ColorDepth property of the ImageList set to Depth24Bit or higher?

Tomalak
Nope, that does not work. Tried all of them, even changing the depth of images, all same result :(
leppie
+2  A: 

The documentation on the .ColorDepth property of the .StateImageList states:

In the .NET Framework version 1.1 or later, the default is Depth8Bit.

It looks like this 'default' is not allowed to be changed. Well, you can change it, but it doesn't do any good.

Looking at the code in Reflector, when the StateImageList property of the the TreeView is set, a new image list is created internally. This image list uses the default value for color depth. And since you cannot change the color depth after creating the imagelist, this pretty much guarantees that the StateImageList can only be displayed at the default color depth.

EDIT: I think I've figured out what's going on here. I have been playing around with images like your shaded circles at varying color depths. Basically, when I take a decent image and convert it to 4-bit color, I get results that look exactly like the images from the StateImageList. Despite the '8-bit' note in the documentation, it appears that the StateImageList is still using 4-bit color depth (the old, old 16-color standard) as the default.

It is only when I use 4-bit images to start with in the imagelist, that I get no changes between the display of the imagelist and stateimagelist.

alt text

I created this image for the imagelist using the old Windows 16-color palette. It looks absolutely terrible, but it didn't change in the stateimagelist.

Stewbob
I tried 8bit images too without success.
leppie
Sounds good, thanks, will try it at work tomorrow :) Maybe I can try prepare the images to look good at 4 bit.
leppie
4 bit images dont work correctly either :( Updated my question with another screenie.
leppie
Hmmm...Curious. I think maybe the difference is that I made 4-bit images using the old 16-color Windows palette, rather than an indexed (adaptive) 16-color palette. Doing it that way, my images looked identical between the imagelist and stateimagelist; which is to say, completely sucky on both.
Stewbob
A: 

ColorDepth property must be set to Depth24Bit before you add image to ImageList. In my case it helped.

That's a no go, see answer below.
leppie