private void btnPost_Click(object sender, EventArgs e) { //将图片以文件流的形式进行保存 FileStream fs = new FileStream(txtPath.Text, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); byte[] imgBytesIn = br.ReadBytes((int)fs.Length); //将流读入到字节数组中 Post post = new Post(this.user.UserId, this.txtTitle.Text.Trim(), this.txtDescribe.Text.Trim(), (float)Convert.ToDouble(this.txtPrice.Text.Trim()), DateTime.Now, (Common.ItemTypes)cmbType.SelectedIndex, (Common.PostTypes)cmbPostType.SelectedIndex, States.待交易, imgBytesIn); bool blnRe = PostServices.AddPost(post); if (blnRe) { MessageBox.Show("发帖成功!"); } else { MessageBox.Show("发帖失败!"); } }