Spo*_*ook 3 c# image imagelist alpha-transparency winforms
我有以下图像:

我正在从资源中读取它,放入ImageList中,然后从ImageList中读取它以在控件的表面上绘制。但是当我这样做时,图像似乎失去了有关Alpha通道的信息:

这是所有相关的代码段:
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;
    }
}
实际上,我在(info.Icon)之前和之后(ilFilters.Images[0])将图像保存到图像列表中。第一个版本正确,第二个-损坏。好像ImageList损坏了图像。
我还尝试将PNG转换为32位BMP图像。没有成功
我正在运行的系统是Windows7。.NET4.5.1,Visual Studio 2013社区。
添加到图像列表时,如何保持图像的Alpha通道?
编辑: 概念验证应用。
从您发布的概念证明中,我找到了使之生效的简单方法。基本上,您必须ImageList在WinForms设计器中定义。
为了提供完整的答案,请按照以下所有步骤进行操作:
Form,ImageList从ToolBox中创建一个。InitializeComponent(),添加您的图片像这样:
ImageList1.Images.AddRange(new[]
{
    Resources.IconPlay,
    Resources.IconPause,
    Resources.IconStop,
    [...]
});
这就是我的做法,效果很好。
另外,在您的示例中,您使用
g.Draw(imageList.Images[0], ...)
代替
imageList.Draw(g, ...)
| 归档时间: | 
 | 
| 查看次数: | 1708 次 | 
| 最近记录: |