如何在 ImageList 中使用半透明图像

How to use Semi-Transparent Images In an ImageList

我有一个包含半透明图像的图像。然后我用它绑定到 ListView。

当我将图像添加到 ImageList 时(在运行时完成),透明部分变为灰色。

作为示例,这显示了将同一图像直接加载到 PictureBox 中,然后通过 ImageList 加载到 PictureBox 中

实际图像是在内存中创建的,但这段代码给出了所述的输出

    Dim tempFilename As String = Path.GetTempFileName
    Dim client As New WebClient()
    client.DownloadFile("http://s32.postimg.org/k2fdrw3wh/Semi.png", tempFilename)
    Dim empIcon = Image.FromFile(tempFilename)

    PictureBox1.BackColor = Color.White
    PictureBox1.Image = empIcon

    PictureBox2.BackColor = Color.White
    Dim imglst As New ImageList With {.ImageSize = New Size(32, 32), .ColorDepth = ColorDepth.Depth32Bit, .TransparentColor = Color.White}
    imglst.Images.Add(empIcon)
    PictureBox2.Image = imglst.Images(0)

PictureBox1 左边 2 右边:

如何让ImageList输出图片到PictureBox1上?

通过以下方式获取图像的透明度:

Dim transColor = CType(empIcon, Bitmap).GetPixel(1, 1)

并将其设置为 ImageList:

Dim imglst As New ImageList With {
    .ImageSize = New Size(32, 32),
    .ColorDepth = ColorDepth.Depth32Bit,
    .TransparentColor = transColor
}