【发布时间】:2015-03-07 00:21:49
【问题描述】:
我有以下图片:
我从资源中读取它,放入 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 图像。没有成功。
我运行的系统是 Windows 7..NET 4.5.1,Visual Studio 2013 Community。
添加到imagelist时如何保持图像的alpha通道?
【问题讨论】:
-
info.Icon是Bitmap类型的吗?如何加载它? -
@bytecode77 是的。它存储在另一个程序集的资源中。我刚刚尝试在添加到 imagelist 之前立即保存它,它仍然有效(alpha 通道)
-
尝试定义
ilFilters.TransparentColor = System.Drawing.Color.Transparent,如果可行的话。这是在黑暗中拍摄的,但是当您在设计器中创建 ImageList 时,WinForms 设计器就是这样做的。 -
@bytecode77 试过了。还是什么都没有……
-
@bytecode77 我创建了一个概念验证应用程序。
标签: c# image winforms alpha-transparency imagelist