日期:2014-05-18 浏览次数:20863 次
private void upload_Click(object sender, EventArgs e) { //二进制来存储图片 FileStream stream = new FileStream(fName, FileMode.Open, FileAccess.Read); byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, (int)stream.Length); stream.Close(); string sql = "insert into 图库(房屋编号,图片)values('" + "1" + "','" + buffer + "')"; SIUD.Insert_and_update(sql); upload.Enabled = false; }
void read_picture() { byte[] imageBytes; string sql = "select * from 图库 where 房屋编号='" + "1" + "'"; SqlDataReader dr = SIUD.dr_read_picture(sql); if(dr.Read()){ imageBytes = (byte[])dr["图片"];//获取图片数据 //将内存流格式化为位图 MemoryStream stream = new MemoryStream(imageBytes); Bitmap bmap = new Bitmap(stream); // ms1.Close(); this.pictureBox1.Image = bmap;//将位图显示在界面的PictureBox控件中 } }