using System.Runtime.Serialization.Formatters.Binary; //... byte[] buffer; using(System.IO.MemoryStream ms = new System.IO.MemoryStream()) { new BinaryFormatter().Serialize(ms, pictureBox1.Image); buffer = ms.GetBuffer(); }//... System.IO.MemoryStream ms; //... Image img = new BinaryFormatter().Deserialize(ms) as Image;
photostream = New IO.MemoryStream picPhoto.Image.Save(photostream, System.Drawing.Imaging.ImageFormat.Jpeg) Dim bt() As Byte = New Byte() {} bt = photostream.ToArray //picPhoto就是picture的name//保存到数据库的时候,就 Dim strSqlinsert As String strSqlinsert = "Insert userinfo (cardno,photo) values(@cardno,@photo)" Dim inscom As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSqlinsert, m_con) command1.Parameters.Add("@cardno", SqlDbType.Int).Value = Trim(txtCardno.Text) command1.Parameters.Add("@photo", SqlDbType.Image).Value = btcommand1.ExecuteNonQuery
using System.Runtime.Serialization.Formatters.Binary;
//... byte[] buffer;
using(System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
new BinaryFormatter().Serialize(ms, pictureBox1.Image);
buffer = ms.GetBuffer();
}//...
System.IO.MemoryStream ms;
//...
Image img = new BinaryFormatter().Deserialize(ms) as Image;
photostream = New IO.MemoryStream
picPhoto.Image.Save(photostream, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim bt() As Byte = New Byte() {}
bt = photostream.ToArray
//picPhoto就是picture的name//保存到数据库的时候,就
Dim strSqlinsert As String
strSqlinsert = "Insert userinfo (cardno,photo) values(@cardno,@photo)"
Dim inscom As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSqlinsert, m_con)
command1.Parameters.Add("@cardno", SqlDbType.Int).Value = Trim(txtCardno.Text)
command1.Parameters.Add("@photo", SqlDbType.Image).Value = btcommand1.ExecuteNonQuery