文件名称:存储图片-java实现微信公众号发送模版消息
文件大小:160KB
文件格式:PDF
更新时间:2024-06-29 10:00:00
操做图片
C# MySQL 图片的存储与读取 一、存储图片 private void button3_Click(object sender, EventArgs e) { if (pictureBox2.Image != null) { //将图片对象image转换成缓冲流imageStream MemoryStream imageStream = new MemoryStream(); pictureBox2.Image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg); //获得图片的字节数组imageByte byte[] imageByte = imageStream.GetBuffer(); //建立数据库连接 MySqlConnection conn = new MySqlConnection("Server=localhost;Uid=root;Password=123;Database=test"); conn.Open(); //设置命令参数 string insertStr="insert into img(image) values(?imageByte)"; MySqlCommand comm = new MySqlCommand(); comm.Connection = conn; comm.CommandText = insertStr; comm.CommandType = CommandType.Text; //设置数据库字段类型MediumBlob的值为图片字节数组imageByte comm.Parameters.Add(new MySqlParameter("?imageByte", MySqlDbType.MediumBlob)).Value = imageByte; //执行命令 try { comm.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } comm.Dispose(); conn.Close(); conn.Dispose(); } }