我有一个包含半透明图像的图像。然后我使用它绑定到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)
右侧左侧2的PictureBox1:
如何让ImageList在PictureBox1上输出图像?
答案 0 :(得分:2)
通过以下方式获取图像的透明度:
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
}