你捕获的是什么类型,Image吗?

解决方案 »

  1.   

    /// <summary>   
    /// 从文件读取 Stream   
    /// </summary>   
    public Stream FileToStream(string fileName)  
    {              
        // 打开文件   
        FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);  
        // 读取文件的 byte[]   
        byte[] bytes = new byte[fileStream.Length];  
        fileStream.Read(bytes, 0, bytes.Length);  
        fileStream.Close();  
        // 把 byte[] 转换成 Stream   
        Stream stream = new MemoryStream(bytes);  
        return stream;  
    }   
      

  2.   

    存  byte[] imagebytes = null;
                using (FileStream fs = new FileStream("D:\\12345.jpg", FileMode.Open))
                {
                    imagebytes = new byte[fs.Length];
                    BinaryReader br = new BinaryReader(fs);
                    imagebytes = br.ReadBytes(Convert.ToInt32(fs.Length));
                }
                SqlConnection con = new SqlConnection("Data Source=FCSDL-DT-002\\SQLEXPRESS;Initial Catalog=stuDB;Integrated Security=True");            con.Open();            string sql = "insert into b(ID,zhiwu,picture)values(@ID,@zhiwu,@picture)";
                System.Data.SqlClient.SqlParameter[] para = new System.Data.SqlClient.SqlParameter[] {
                new System.Data.SqlClient.SqlParameter("@ID",12),
                    new System.Data.SqlClient.SqlParameter("@zhiwu","dahui"),
                new System.Data.SqlClient.SqlParameter("@picture",imagebytes)
                };            //string sql = string.Format("insert into b(ID,zhiwu,picture)values({0},'{1}',{2})", 9, "xiaohuilang", imagebytes);            SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.AddRange(para);
                int resulet = cmd.ExecuteNonQuery();
                con.Close();
    取  byte[] imagebytes = null;            SqlConnection con = new SqlConnection("Data Source=FCSDL-DT-002\\SQLEXPRESS;Initial Catalog=stuDB;Integrated Security=True");            con.Open();            string sql = "select * from b where ID=11";            SqlCommand cmd = new SqlCommand(sql, con);            SqlDataReader read = cmd.ExecuteReader();
                while (read.Read())
                {
                    imagebytes = (byte[])read["picture"];
                }
                read.Close();
                con.Close();            MemoryStream ms = new MemoryStream(imagebytes);
                Bitmap bmpt = new Bitmap(ms);
                this.pictureBox1.Image = bmpt;
      

  3.   

    如果是Image 则               
     MemoryStream ms=new MemoryStream();
                                     img.Save(ms, ImageFormat.Jpeg);//img为你的图片
                    byte[] byt = new byte[ms.Length];
                    byt = ms.GetBuffer();
      

  4.   

    感谢,可是我不知道为什么使用摄像头获取到的image值为空,请问如何获取
    Image images = picturebox1.Image;
      

  5.   

    http://hi.baidu.com/tdskee/blog/item/ac3ce8193b081b72dab4bde2.html
      

  6.   

    http://www.codeproject.com/KB/cs/WebCamService.aspx 用webcam获取,你看看。
      

  7.   

    上面那个有些繁琐,我觉得还是调用api好一些,那个要依赖服务。
    我这里没摄像头不能帮你试。
    这个应该可以。
    http://blog.sina.com.cn/s/blog_6ca9cc1f0100pi0d.html