使用MySQL 儲存與擷取影像
將影像儲存到資料庫
到成功將🎜>到成功將圖像保存到MySQL資料庫,請確保執行以下程式碼:
<br>Dim filename As String = txtName.Text ".jpg"<br>Dim FileSize As UInt32<p>conn.Close() </p><p>將mstream 調暗為新System.IO.MemoryStream()<br>PbPicture.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)<br>Dim arrImage() As Byte = mstream.GetBuffer()</p>Dim arrImage() As Byte = mstream.GetBuffer()<p><size>File = mstream.Length<br>Dim sqlcmd As New MySqlCommand<br>Dim sql As String<br>mstream.Close()</size></p> <p>sql =「插入[您的表格](圖片、檔案名稱、檔案大小)</p><pre class="brush:php;toolbar:false"> VALUES(@File, @FileName, @FileSize)"
嘗試
conn.Open() With sqlcmd .CommandText = sql .Connection = conn .Parameters.AddWithValue("@FileName", filename) .Parameters.AddWithValue("@FileSize", FileSize) .Parameters.AddWithValue("@File", arrImage) .ExecuteNonQuery() End With
捕獲ex作為異常
MsgBox(ex.Message)
最後
conn.Close()
結束嘗試
擷取影像🎜>顯示圖片PictureBox中的資料庫,使用以下程式碼:
<p>Dim 適配器As New MySqlDataAdapter</p>adapter.SelectCommand = Cmd<p><br>data = New Data<br>> = New MySqlDataAdapter("從[yourtable] 選取圖片", conn)</p><p>commandbuild = New MySqlCommandBuilder(adapter)</p>adapter.Fill(data)<p></p>Dim lb( ) As Byte = data.Rows(0).Item("picture") <p>Dim lstr As New System.IO.MemoryStream(lb)<br>PbPicture.Image = Image.FromStream(lstr)</p>PbPicture. SizeMode = PictureBoxSizeMode.StretchImage<p>lstr.Close()<br></p>
以上是如何使用 MySQL 儲存和檢索映像?的詳細內容。更多資訊請關注PHP中文網其他相關文章!