这是从特定文件夹中检索图像并将其显示在列表视图中的代码。它以大图标显示图像,但我想从数据库中检索图像。
以下是代码:
ListView1.Items.Clear()
'retrieve image from specific folder
Dim dirFiles() As String = IO.Directory.GetFiles("D:\Capture")
Dim _imgList As New ImageList
Dim imgSize As New Size
'setting up custom size
imgSize.Width = 155
imgSize.Height = 255
ListView1.LargeImageList = _imgList
ListView1.LargeImageList.ColorDepth = ColorDepth.Depth32Bit
Dim count As Integer = 0
Dim item As New ListViewItem
For Each dirFile As String In dirFiles
Dim imgFilename As String = IO.Path.GetFileNameWithoutExtension(dirFile)
Dim img As New System.Drawing.Bitmap(dirFile)
Dim imgImage As Image = Image.FromFile(dirFile)
_imgList.ImageSize = imgSize
_imgList.Images.Add(img.Clone)
ListView1.Items.Add(imgFilename, count)
count += 1
Next
我尝试过的教程不起作用,因为在将图像保存到数据库之前将图像转换为字节数组,在我的工作中我保存了图像的路径。有人可以帮帮我吗?