不好意思“3”中的“数据为”是写错了的,应该是“数据库”
哪位有成功例子发一份给我吧,谢谢[email protected]

解决方案 »

  1.   

    你可以把图片转换成一段数据流,然后把流保存到数据库中(image字段)
    读的时候也一样,把数据流转换为Picture
      

  2.   

    1、录入员工资料:怎么打开一个图片文件并显示在aspx页面的Image1中?
    让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;
    }
    }
      

  3.   

    SQLserver2000现在只支持以二进制格式存放图片,所以在程序中要用BYTE数组存取
      

  4.   

    非常感谢楼上的各位 的热心帮助,哪位再仔细的说说c#的winform中存取相片的例子呀!
      

  5.   

    图片TO数据流:
    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();
      

  6.   

    如何读取、保存图片我在这个帖子中给了详细的解答,你看一下:
    http://expert.csdn.net/Expert/topic/2643/2643679.xml?temp=.7120478
      

  7.   

    这样更好.图片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();
      

  8.   

    to 984437(NewStar) 
    pictureBox1.Image.Save(s,System.Drawing.Imaging.ImageFormat.bmp);上面代码出错,提示如下:
    F:\asp\人力资源\basedb.cs(176): 不可访问“System.Drawing.Imaging.ImageFormat.bmp”,因为它受保护级别限制
      

  9.   

    不好意思,没仔细看。Image.Save()中的第二个参数是System.Drawing.Imaging.ImageFormat的一个对象.ImageFormat imagef = new ImageFormat(参数为guid) 
    guid : 指定特定图像格式的 Guid 结构。不过具体传什么进去,我也不知道。学习.
      

  10.   

    to 984437(NewStar) 可以了!谢谢大家!