asp.net上传图片的时候将图片转为二进制流 然后在winfrom中读取二进制流后转为图片在pictureBox显示解决思路
asp.net上传图片的时候将图片转为二进制流 然后在winfrom中读取二进制流后转为图片在pictureBox显示
asp.net:上传图片的时候将图片转为二进制流 数据库改字段类型为image
然后在
winfrom中读取二进制流后转为图片在pictureBox显示
问题二:
pictureBox点击事件中获取图片然后将图片转为二进制数据流
以上都是公用的一个字段
------解决方案--------------------
将图片存为文件吧,这样简单点,效率高,将你的二进制流写入文件就行。
------解决方案--------------------
asp.net:上传图片的时候将图片转为二进制流 数据库改字段类型为image
然后在
winfrom中读取二进制流后转为图片在pictureBox显示
问题二:
pictureBox点击事件中获取图片然后将图片转为二进制数据流
以上都是公用的一个字段
------解决方案--------------------
将图片存为文件吧,这样简单点,效率高,将你的二进制流写入文件就行。
------解决方案--------------------
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;