话不多说,上代码先- -
private void WriteBuffer()
        {
            try
            {
                TcpClient tcp = new TcpClient("192.168.4.227", 9002);
                Byte[] sendbyte = new Byte[255];
                string send = "/home/coder/v2.jpg";
                //生成NetworkStream实例,用于发送基础数据流。
                NetworkStream netstream = new NetworkStream(tcp.Client);
                sendbyte = System.Text.Encoding.GetEncoding(0).GetBytes(send.ToCharArray());
                netstream.Write(sendbyte, 0, sendbyte.Length);//向socket服务器发送信息。
                netstream.Flush();
                //接收
                using (FileStream fs = new FileStream("1.jpg", FileMode.CreateNew))
                {
                    byte[] buffer = new byte[1024];
                    int nRecv;
                    tcp.ReceiveBufferSize = 1024;
                    while ((nRecv = tcp.Client.Receive(buffer)) > 0)
                    {
                        fs.Write(buffer, 0, nRecv);
                    }
                    fs.Close();
                }
            }
            catch (Exception ex)
            {                throw ex;
            }
        }
        private void dtShowMonitor_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            WriteBuffer();
            MySqlConnection db = new MySqlConnection(ClassPublic.strConn);
            db.Open();
            DataSet ds = new DataSet();
            string sql = "select * from t_Captrue";
            MySqlDataAdapter da = new MySqlDataAdapter(sql, db);
            da.Fill(ds, "t_Captrue");
            if (ds != null)
            {
                this.picShowImage.Image = Image.FromFile("1.jpg", false);
                this.labTime.Text = ds.Tables["t_Captrue"].Rows[e.RowIndex][1].ToString();
            }
        }前面是一个方法 发送请求和接收服务器图片路径 现在的问题是
我图片已经显示在本地了 但是每次点击datagridview的行时 它会报该图片已经存在 我想知道如何判断这个图片已经存在?
我把服务器的数据显示到了datagridview 每当我点击一行 相应的图片就显示在picturebox 但是现在我做的是一个车牌识别系统
当大图片显示出来的时候 我还想讲小图片显示出来 就是大图片的左下角有一个小图片 不知道谁做过这个 是不是有2个pictureBox就可以了?

解决方案 »

  1.   

    1、可以using (FileStream fs = new FileStream("1.jpg", FileMode.CreateNew)) 修改为using (FileStream fs = new FileStream("1.jpg", FileMode.Create))
    2、你的picture控件中不使用图片的路径,而是直接使用服务器端获取到的图片二进制流,不保存在本地了。
      

  2.   

    查询后,来判断啊;
    给你一个实例,是用来判断用户注册时,输入的用户名是否已经存在:
     SqlConnection myConnection;
            SqlCommand cmd;
            myConnection = new SqlConnection(myConnectionString);
                cmd = new SqlCommand();
                cmd.Connection = myConnection;
                string sql;
                sql = "select user from dr where ID='" + textBox1.Text.Trim() + "'";
                cmd.CommandText = sql;
                myConnection.Open();
                if (cmd.ExecuteScalar() == null)
                {
                    MessageBox.Show("不存在该用户,您可以用这个账号注册!");
                }
                else
                {
                    MessageBox.Show("该用户已经存在,请重新输入账号注册!");
                    textBox1.Text = "";
                }