如何在MySQL中插入/检索图形?

时间:2018-09-23 08:29:04

标签: mysql-workbench vb.net-2010

我有一个上面有图片的图片框,然后有一个代码,用户可以在该图片框上应用绘图,但是当我尝试使用“保存”按钮保存图片框时,它仅将图片保存在图片框上,但是我在图片框上应用的图形尚未保存。我该怎么做才能将绘图保存在图片框上?

  

这是我的保存按钮

Private Sub btnsave_Click(sender As System.Object, e As System.EventArgs) Handles btnsave.Click
    Dim mstream As New System.IO.MemoryStream()
    pbtest.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
    Dim arrImage() As Byte = mstream.GetBuffer()

    MysqlConn = New MySqlConnection
    MysqlConn.ConnectionString =
        "server=localhost;userid=root;password=rico;database=god;"


    Try
        MysqlConn.Open()
        COMMAND.CommandText = "insert into god.precord (ID,LastName,FirstName,MiddleName,Address,ContactNo,Gender,Birthdate,Age,picture) values (@id,@lastname,@firstname,@middlename,@address,@contactno,@gender,@birthdate,@age,@picture)"
        COMMAND.Connection = MysqlConn
        COMMAND.CommandType = CommandType.Text
        COMMAND.Parameters.AddWithValue("@id", txtid.Text)
        COMMAND.Parameters.AddWithValue("@lastname", txtlastname.Text)
        COMMAND.Parameters.AddWithValue("@firstname", txtfirstname.Text)
        COMMAND.Parameters.AddWithValue("@middlename", txtmiddlename.Text)
        COMMAND.Parameters.AddWithValue("@address", txtaddress.Text)
        COMMAND.Parameters.AddWithValue("@contactno", txtcontactno.Text)
        COMMAND.Parameters.AddWithValue("@gender", txtgender.Text)
        COMMAND.Parameters.AddWithValue("@birthdate", dtpbirthdate.Text)
        COMMAND.Parameters.AddWithValue("@age", txtage.Text)
        COMMAND.Parameters.AddWithValue("@picture", arrImage)
        COMMAND.ExecuteNonQuery()
        MessageBox.Show("Data Saved")
        MysqlConn.Close()

    Catch ex As MySqlException
        MessageBox.Show(ex.Message)
    Finally
        MysqlConn.Dispose()
    End Try
    dbDataSet.Clear()
    load_table()
End Sub
  

这就是我在图片框上绘制代码的方式。

Public Class Form1
Dim g As System.Drawing.Graphics
Dim mybrush = Brushes.Black()

 Private Sub PictureBox40_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox40.MouseDown
    down = True
End Sub

Private Sub PictureBox40_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox40.MouseMove
    If down = True Then
        PictureBox40.CreateGraphics.FillEllipse(mybrush, e.X, e.Y, 5, 5)
    End If
End Sub

Private Sub PictureBox40_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox40.MouseUp
    down = False
End Sub

感谢您可以提供的帮助!

0 个答案:

没有答案