winfrom存储图片
用C#编写winform 存储图片到sql数据库上的代码是怎么样的 怎么在查询的时候给显示在pictruebox上啊请各位大哥帮忙解决下啊 --------------------编程问答-------------------- 写winfrom的贴一律不理 --------------------编程问答-------------------- 存图片路径吧 --------------------编程问答--------------------
我也知道路径存储啊 但是存储进去的二进制数据好像是破损的 图片显示不出来 --------------------编程问答-------------------- 存成二进制
然后读出来再还原为图片 --------------------编程问答--------------------
能给点源码参考下不 我写了但是还是出现参数错误问题啊 --------------------编程问答-------------------- 用bitmap 读照片。 转化成二进制流的字符串。然后储存进数据库 --------------------编程问答--------------------
能否给点源码给参考下 --------------------编程问答-------------------- Stream ms;
byte[] picbyte;
OpenFileDialog ofdSelectPic = new OpenFileDialog();
if (ofdSelectPic.ShowDialog() == DialogResult.OK)
{
if ((ms = ofdSelectPic.OpenFile()) != null)
{
picbyte = new byte[ms.Length];
ms.Position = 0;
ms.Read(picbyte, 0, Convert.ToInt32(ms.Length));
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "";
sql = "Insert into Person(Photo) values(@Image)";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add("@Image", SqlDbType.VarBinary);
cmd.Parameters["@Image"].Value = picbyte;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
ms.Close();
}
}
SqlConnection conn=new SqlConnection();
conn.ConnectionString="";
string strSql="";
SqlCommand cmd=new SqlCommand(strSql,conn);
conn.Open();
SqlDataReader reader=cmd.ExecuteReader();
reader.Read();
MemoryStream ms=new MemoryStream((byte[])reader["Photo"]);
Image image=Image.FromStream(ms,true);
reader.Close();
conn.Close();
picturebox1.Image=image;
FileStream mystream=new FileStream("D:\\A.jpg",FileMode.Open,FileAccess.Read);
long len=mystream.Length;
mycmd.Parameters.Add("@image",SqlDbType.Image,(int)len,"picture");
mycmd.Parameters["@image"].Direction=System.Data.ParameterDirection.Input;
byte []box=new byte[len];
mystream.Read(box,0,(int)len);
mycmd.Parameters["@image"].Value=box;
--------------------编程问答--------------------
FileStream mystream=new FileStream("D:\\A.jpg",FileMode.Open,FileAccess.Read);
这里面的路径是什么用的啊 请教 --------------------编程问答--------------------
--------------------编程问答-------------------- 用这个以后怎么显示出来 --------------------编程问答-------------------- wuyq11 的方法很好,强烈推荐。 --------------------编程问答--------------------
private void btnUpload_Click(object sender, EventArgs e)
{
openPic.Title = "Choose Picture";
openPic.Filter = "JPEG(*.jpg)|*.jpg|PNG(*.png)|*.png";
if (openPic.ShowDialog() == DialogResult.OK)
{
if (File.Exists(openPic.FileName))
{
if (openPic.OpenFile().Length > 1024 * 1024 * 2)
{
MessageBox.Show("图片不得超过2M");
return;
}
string image = openPic.FileName;
string picpath = openPic.FileName;
Guid guid = Guid.NewGuid();
this.txtPhoto.Text = openPic.FileName;
if (!Directory.Exists(Application.StartupPath + "\\image"))
{
Directory.CreateDirectory(Application.StartupPath + "\\image");
}
this.txtPhoto.Tag = Application.StartupPath + "\\image\\" + guid.ToString() + ".jpg";
File.Copy(openPic.FileName, Application.StartupPath + "\\image\\" + guid.ToString() + ".jpg");
picPhoto.Image = Image.FromFile(Application.StartupPath + "\\image\\" + guid.ToString() + ".jpg");
picPhoto.ImageLocation = Application.StartupPath + "\\image\\" + guid.ToString() + ".jpg";
}
else
{
MessageBox.Show("图片不能为空");
return;
}
}
}
FileStream mystream=new FileStream("D:\\A.jpg",FileMode.Open,FileAccess.Read);
能否解释下那个路径是什么意思 --------------------编程问答-------------------- 各位高手 帮忙解决下啊
补充:.NET技术 , C#