如何实现在C#WinForm程序中实现图片的上传功能,不是将图片保存到服务端指定的文件夹,而是将图片通过转换保存到数据库的表中,数据库的表应该如何建立,字段使用什么类型;对已经上传的图片,如何下载下来,在PictureBox中显示。求指教,谢了。

解决方案 »

  1.   

    google 数据库二进制保存图片 ado.net
      

  2.   

    存入数据库用 byte[]对应的数据类型  ,sql里面有好几种,貌似image类型也是有的
    读取就是
    System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes);
    Image.FromStream(ms);
      

  3.   

    用二进制存取,在数据库用image存放
      

  4.   

    http://zhidao.baidu.com/question/528267717.html
      

  5.   

    最近刚实现了这个功能
    先添加控件OpenFIleDialog,按钮,文本框
    按钮事件
    openFIleDialog.InitialDirectory = "";
    openFIleDialog.Filter = "图片文件(*.jpg)|8.jpg|所有文件(*.*)|*.*";
    openFIleDialog.RestoreDirectory = true;
    openFIleDialog.Multiselect = true;
    if(openFIleDialog.ShowDialog() == DialogResult.OK)
    {
      txtPicPath.Text = openFileDialog.FileName;
    }
    将图片转换成二进制的方法
    peivate byte[] ChangePicType(string picPath)
    {
    FileStrem fs = new FileStream(picPath,FileMode.Open,FileAccess.Read);
    byte[] buffByte = new byte[fs.length];
    fs.Read(buffByte ,0,Convert.ToInt32(fs.length));
    fs.Flush();
    fs.Close();
    return  buffByte;
    }数据库的字段类型Bolb
    数据库保存方法
    ForOracle  forOracle = new ForOracle();
    forOracle.AddParameters("ZP",zp,DataType.Blob);在PictureBox中显示的方法
    pictureBox.Image = GetIamge(dr["ZP"]);GetIamge()方法代码
    private Iamge GetIamge(byte[] buffer)
    {
    MemoryStream ms = new MemoryStream(buffer);
    Iamge img = Iamge.FromStream(ms);
    return img;
    }希望对楼主有用啦! 记得给分哦,绝对亲自手打的!
      

  6.   

     public class ImgCovert
        {
            //根据图片文件的路径使用文件流打开,并保存为byte[] 
            public static byte[] GetPictureData(string imagepath)
            {
                FileStream fs = new FileStream(imagepath, FileMode.Open);
                byte[] byData = new byte[fs.Length];
                fs.Read(byData, 0, byData.Length);
                fs.Close();
                return byData;
            }
            //参数是Byte[]类型,返回值是Image对象: 
            public static System.Drawing.Image ReturnPhoto(byte[] streamByte)
            {
                System.IO.MemoryStream ms = new System.IO.MemoryStream(streamByte);
                System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
                return img;
            }
        }
      

  7.   

    不同的数据库建立不同的字段,oracl 是blog,ms 是image。然后将图片转化为二进制流存入字段即可