ImageList with Transparent image for treeview

S

SQACSharp

Hi,

I'm trying to do a simple thing since at least 5 hours :(

At runtime I add several icon to an imageList and use it later to fill
a treeview.

When adding the icon to the ImageList the transparency is lost and a
blue background is displayed instead.

Here is some code to explain my problem :

//IconHandle is already set to a valid HICON; the Icon of a wordpad
mainWindow by example
....
Icon AppIcon = new Icon(IconHandle );
Bitmap Bmp = new Bitmap(AppIcon.Width, AppIcon.Height);
Graphics g = Graphics.FromImage(Bmp);
g.DrawImage(Bmp,new Point(0,0)); //This ensure transparency
g.Dispose();
pictureBox1.Image = Bmp; // The image is correctly displayed in a
picturebox
MyImageList.Images.Add(Bmp);
pictureBox2.Image = MyImageList.Images[MyImageList.Images.Count-1];
// The image is INCORRECTLY displayed with a "random" color instead of
the transparency color

Question :
How can I add an image to an imageList and keep the transparency. I
already try almost everyting possible with no luck.

Thanks
 
S

SQACSharp

Setting the imageList to 32bit solve the problem. But this sounds like
a bad idea since the system may not be configured to 32bit. Look like
I will have to track the system config to correctly set the image list
ColorDepth. At least it work now :)
 
P

Peter Duniho

Setting the imageList to 32bit solve the problem. But this sounds like
a bad idea since the system may not be configured to 32bit. Look like
I will have to track the system config to correctly set the image list
ColorDepth. At least it work now :)

In general, the .NET drawing API should work well enough regardless of the
actual current video setting. And if you expect for your transparency to
be preserved, you have to be using a bitmap format that includes
transparency information (e.g. 32-bit ARGB).

You can easily test whether this fails to work under different video
settings; just try your program after you've changed the video settings to
24-bit, 16-bit, etc. The quality of the output may be reduced, but the
transparency should otherwise work fine.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top