//数据库,图片字段为text类型,存储时也是转成了base64存储
#region 读取数据库 base64编码的图片
byte[] bytefile;
mConn = new SQLiteConnection("Data Source=" + mDbPath);
if (mConn.State != ConnectionState.Open)
{
mConn.Open();
}
String sql = String.Format("SELECT 图片模板 FROM 表名 where ID='" + dataid + "'");//sql语句
SQLiteCommand cmd = new SQLiteCommand(sql, mConn);
string fileName = cmd.ExecuteScalar().ToString();//filename接收sql语句的结果,就是对应id的图片
bytefile = Convert.FromBase64String(fileName);//编码转图片
MemoryStream ms = new MemoryStream(bytefile);
Image img = Image.FromStream(ms);
this.pictureBox1.Image = img;//绑定控件的image属性
if (mConn.State != ConnectionState.Closed)//关闭内存
{
mConn.Close();
}
#endregion
winform picturebox读取数据库 base64编码的图片
于 2022-03-21 13:46:49 首次发布