将不同大小的图像添加到列表视图中

时间:2015-10-13 00:09:51

标签: vb.net listview

我有一个列表视图,我可以添加不同大小的图像,例如。 123x23,23,43等等.. 我如何继续解决这个问题。我知道listview有一个tileize属性,但它设置了所有tile的一般大小 尝试使用图像列表,更改图像列表imagesize也没有帮助...下面是用于将图像添加到列表框的代码

代码中的imglist是一个加载了所有必需图像的图像列表。

Private Sub frm_load_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Form1.ListViewEx1.LargeImageList = imglist

            For i = 0 To imglist.Images.Count - 1
                Dim x = Form1.ListViewEx1.Items.Add(New ListViewItem("", i))
                x.Tag = imglist.Images.Keys(i).ToString
            Next

            Form1.lbl_status1.Text = "Image Count: " & Form1.ListViewEx1.Items.Count  
End sub

1 个答案:

答案 0 :(得分:-1)

我遇到了同样的问题。 我找到了这个,这对我有用:Click here

Public Sub LoadImageList(ByVal ImagePath As String, ByVal Key As String)

Dim picImage As Image = Nothing
Dim final_Bitmap As Bitmap = Nothing
Dim org_Image As Bitmap = Nothing

If File.Exists(ImagePath) Then
        picImage = Image.FromFile(ImagePath)
'********************* Drawing the Image in proportion to the imagelist Size Here ****************
        Dim proportion As Integer = 0
        Dim startx As Decimal = 0
        Dim startY As Decimal = 0
        Dim drawwidth As Decimal = 0
        Dim drawheight As Decimal = 0
        org_Image = New Bitmap(picImage)
        final_Bitmap = New Bitmap(ImageList1.ImageSize.Width, ImageList1.ImageSize.Height)
        Dim gr As Graphics = Graphics.FromImage(final_Bitmap)
        Dim factorscale As Decimal
        factorscale = org_Image.Height / org_Image.Width
        drawwidth = final_Bitmap.Width
        drawheight = final_Bitmap.Width * factorscale
        If drawheight > final_Bitmap.Height Then
                proportion = 1
                factorscale = org_Image.Width / org_Image.Height
                drawheight = final_Bitmap.Height
                drawwidth = final_Bitmap.Height * factorscale
        End If
        startx = 0
        startY = final_Bitmap.Height - drawheight
        gr.DrawImage(org_Image, startx, startY, drawwidth, drawheight)
        ImageList1.Images.Add(Key, final_Bitmap)
        org_Image.Dispose()
        final_Bitmap.Dispose()
'************************** End Loading the Image****************
End If

End Sub