I've got the following image:
I'm reading it from resources, putting into ImageList and then reading it from ImageList to draw on my control's surface. But when I'm doing that, image seems to loose information about alpha channel:
Here are all relevant pieces of code:
Program.cs
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
MainForm.cs
ilFilters = new ImageList()
{
ColorDepth = ColorDepth.Depth32Bit,
ImageSize = new Size(16, 16)
};
// (...)
if (info.Icon != null)
{
if (info.Icon.Width == 16 && info.Icon.Height == 16)
{
ilFilters.Images.Add(info.Icon);
index = ilFilters.Images.Count - 1;
}
}
I actually saved the image before (info.Icon
) and after (ilFilters.Images[0]
) putting it into the image list. The first version was correct, second - corrupted. Seems like ImageList damaged the image.
I also tried converting the PNG to 32-bit BMP image. No success.
The system I'm running is Windows 7. .NET 4.5.1, Visual Studio 2013 Community.
How can I keep alpha channel of the image when adding to imagelist?
Edit: Proof of concept application.
info.Icon
of typeBitmap
and how do you load it? – ParalyticilFilters.TransparentColor = System.Drawing.Color.Transparent
if that works. It's a shot in the dark, but that's what the WinForms designer does when you create an ImageList in the designer. – Paralytic