我正在使用此方法从数据库中获取图像字节。
cmd.CommandText = "select imagedate from projectimages where imagename = '" + _
ListBox1.Text + "' and CSVprojectref=checksum('" + textboxFileRef.Text + "')"
Dim img As Object = cmd.ExecuteScalar()
现在我该如何将这个图像添加到PictureBox.image中。我在检索图像并在PictureBox中显示它方面遇到了很多问题。
在SQL数据库中,数据类型为Image,我使用以下代码将图像保存到数据库中:
Dim ms As New IO.MemoryStream
If imageFilename.Contains("jpeg") Or imageFilename.Contains("jpg") Then
imageUpload.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
End If
If imageFilename.Contains("png") Then
imageUpload.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
End If
If imageFilename.Contains("gif") Then
imageUpload.Save(ms, System.Drawing.Imaging.ImageFormat.Gif)
End If
If imageFilename.Contains("bmp") Then
imageUpload.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
End If
Dim bytes() As Byte = ms.ToArray
Dim img As String = Convert.ToBase64String(bytes)
Dim cmd As New OleDb.OleDbCommand("insert projectimages values('" + imageNameTemp + "','" + img + "',CHECKSUM('" + textboxFileRef.Text + "'))", con)
cmd.ExecuteNonQuery()