【问题标题】:Adding images of different sizes into a listview将不同大小的图像添加到列表视图中
【发布时间】:2015-10-13 00:09:50
【问题描述】:

我有一个列表视图,我向其中添加不同大小的图像,例如。 123x23、23,43 等等.. 我该如何继续解决这个问题。我知道 listview 有一个 tilesize 属性,但它设置了所有图块的一般大小 尝试使用图像列表,更改图像列表图像大小也无济于事......这是我用来将图像添加到列表框的代码

代码中的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

【问题讨论】:

    标签: vb.net listview


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2016-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-15
      • 2020-05-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多