MemoryStream ms = new MemoryStream()
pictureBox1.Image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg)
byte[] img = ms.ToArray()
再将img写入数据库就行了。
读取img数据
byte[] curImg=rs["img"]
this.pictureBox1.Image=new Bitmap(new MemoryStream(img))
直接使用企业管理器好像没有办法 *** 作吧,通过软件或自己做个小软件读取。public void LoadToMemoryAndDisable(string serverAdress, string database)
{
//读取数据库中图片到内存.并显示
SqlConnection conn = new SqlConnection("server=" + serverAdress + "integrated security = sspidatabase = " + database)
SqlCommand cmd = new SqlCommand("select * from imgtable where imgname like '%bmp%'", conn)
conn.Open()
SqlDataReader dr
try
{
dr = cmd.ExecuteReader()
dr.Read()
System.Data.SqlTypes.SqlBinary sb = dr.GetSqlBinary(2)
//或byte[] imageData = (byte[])dr[2]
MemoryStream ms = new MemoryStream(sb.Value)//在内存中 *** 作图片数据
Bitmap bmp = new Bitmap(Bitmap.FromStream(ms))
this.pictureBox1.Image = bmp
dr.Close()
}
catch (Exception ex)
{
MessageBox.Show(ex.Message)
}
finally
{
conn.Close()
}
}
#endregion
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)