如何快速/更快地将图片加载到图片框

时间:2017-02-19 07:46:55

标签: mysql vb.net image visual-studio-2010

我有这个代码将图像从MySql数据库加载到picturebox。但加载图像大约需要4-5秒。

' this code if for SAVING IMAGE to MySQL database.
Public Function ConvertToBytes(ByVal img As PictureBox) As Byte()

    Dim msPic As New MemoryStream
    img.Image.Save(msPic, System.Drawing.Imaging.ImageFormat.Bmp)
    Dim Mybyte() As Byte = msPic.GetBuffer
    Return Mybyte

End Function

' this code if for RETRIEVING IMAGE FROM MySQL database.

sql_connection = New MySqlClient.MySqlConnection(conn.connect)
sql_connection.Open()
Dim arrImage() As Byte
sql_command = New MySqlClient.MySqlCommand("SELECT * FROM tblCatalog WHERE IDCardNo = '" & TEXTBOX1.Text & "'", sql_connection)
sql_command.CommandTimeout = 1000
sql_reader = sql_command.ExecuteReader()
While (sql_reader.Read())
    arrImage = sql_reader("Picture")
    Dim mstream As New System.IO.MemoryStream(arrImage)
    PictureBox3.Refresh()
    PictureBox3.Image = Image.FromStream(mstream)
End While
sql_reader.Close()

我将代码放入Timer_tick,我也尝试了按钮事件。但结果仍然是一样的。有人可以帮助我吗?我希望当我按下回车键或点击按钮时,它会快速加载图像。

0 个答案:

没有答案