这样更好.图片TO数据流: MemoryStream s = new MemoryStream(); pictureBox1.Image.Save(s,System.Drawing.Imaging.ImageFormat.bmp); byte[] b = s.ToArray(); s.Close(); 然后你可通过dr[3] = b;/*dr[3]为image字段值*/ 然后保存到数据库存中.数据流TO图片 注dr[3]为我在数据库中image字段读出的值 先读出记录,然后 byte[] b = (byte[])dr[3]; MemoryStream s = new MemoryStream(b); Bitmap bmp = new Bitmap(stream); System.Drawing.Image image = bmp; pictureBox1.Image = image; s.Close();
to 984437(NewStar) pictureBox1.Image.Save(s,System.Drawing.Imaging.ImageFormat.bmp);上面代码出错,提示如下: F:\asp\人力资源\basedb.cs(176): 不可访问“System.Drawing.Imaging.ImageFormat.bmp”,因为它受保护级别限制
不好意思,没仔细看。Image.Save()中的第二个参数是System.Drawing.Imaging.ImageFormat的一个对象.ImageFormat imagef = new ImageFormat(参数为guid) guid : 指定特定图像格式的 Guid 结构。不过具体传什么进去,我也不知道。学习.
读的时候也一样,把数据流转换为Picture
让Image1的src指向存放图片的路径,如:
this.Image1.Src="//temp//tmp.bmp";
2、保存员工资料:怎么把aspx页面的Image1中的相片存入数据库中?
利用存储过程....
3、浏览员工资料:怎么把数据为中相片显示在aspx页面的Image1中?
读取图片,如:
/// <summary>
/// 根据人员ID填充图片到Images/TempImages下:*.bmp
/// 再从Images/TempImages下取出照片绑定到Image控件的src。
/// </summary>
/// <param name="id"></param>
private void GetPicture(object id)
{
if(id.ToString()=="")
return;
try
{
string sql="select Photo from SalFund..Sal_HumanInfo_Photograph where Num = '"+id.ToString()+"'";
SqlConnection conn=new SqlConnection(QueryAndStatistic.CommonClass.sConnectionString);
SqlDataAdapter da=new SqlDataAdapter(sql,conn);
DataSet dss=new DataSet();
da.Fill(dss,"Sal_HumanInfo_Photograph");
if(dss.Tables[0]==null || dss.Tables[0].Rows.Count==0)//表示没有查出图片
{
this.photo.Visible=false;
this.noPhoto.Visible=true;
return;
}
byte[] MyData = null;
MyData = (byte[])dss.Tables[0].Rows[0]["Photo"]; int ArraySize = new int();
ArraySize = MyData.GetUpperBound(0); FileStream fs = new FileStream(Server.MapPath("temp//tmp.bmp"), FileMode.OpenOrCreate, FileAccess.Write); fs.Write(MyData, 0,ArraySize+1); // don't ask me why, but I had to add 1 here for this to work
fs.Close();
//Bitmap image = new Bitmap(Server.MapPath("temp//tmp.bmp"));
//this.photo.Src=Server.MapPath("temp//tmp.bmp");//.Image = new Bitmap("tmp.gif");
this.photo.Src="temp//tmp.bmp";
this.noPhoto.Visible=false;
this.photo.Visible=true;
}
catch(Exception err)
{
return;
}
}
MemoryStream s = new MemoryStream();
pictureBox1.Image.Save(s,System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] b = s.ToArray();
s.Close();
然后你可通过dr[3] = b;/*dr[3]为image字段值*/
然后保存到数据库存中.数据流TO图片
注dr[3]为我在数据库中image字段读出的值
先读出记录,然后
byte[] b = (byte[])dr[3];
MemoryStream s = new MemoryStream(b);
pictureBox1.Image = Image.FromStream(s);
s.Close();
http://expert.csdn.net/Expert/topic/2643/2643679.xml?temp=.7120478
MemoryStream s = new MemoryStream();
pictureBox1.Image.Save(s,System.Drawing.Imaging.ImageFormat.bmp);
byte[] b = s.ToArray();
s.Close();
然后你可通过dr[3] = b;/*dr[3]为image字段值*/
然后保存到数据库存中.数据流TO图片
注dr[3]为我在数据库中image字段读出的值
先读出记录,然后
byte[] b = (byte[])dr[3];
MemoryStream s = new MemoryStream(b);
Bitmap bmp = new Bitmap(stream);
System.Drawing.Image image = bmp;
pictureBox1.Image = image;
s.Close();
pictureBox1.Image.Save(s,System.Drawing.Imaging.ImageFormat.bmp);上面代码出错,提示如下:
F:\asp\人力资源\basedb.cs(176): 不可访问“System.Drawing.Imaging.ImageFormat.bmp”,因为它受保护级别限制
guid : 指定特定图像格式的 Guid 结构。不过具体传什么进去,我也不知道。学习.