我使用两个单独的按钮来旋转图像并保存图像。不知何故,轮换正在发挥作用。但是保存(更新)不起作用。我试图找到问题,但我不能。
错误是“值不能为空。参数名称编码器”。 我最好的猜测是RotateFlip以某种方式影响了图片框。
此致
这是我的代码,
private void btnRotate_Click(object sender, EventArgs e)
{
if (pictureBoxProfile.Image != null)
{
pictureBoxProfile.Image.RotateFlip(RotateFlipType.Rotate90FlipNone);
pictureBoxProfile.Refresh();
}
else
{
MessageBox.Show("Select an Image");
}
}
private void btnSave_Click(object sender, EventArgs e)
{
if (txtShortName.Text == "" || txtPhoneNumberM.Text == "" || txtFullName.Text == "" || gender.Text == "" || richTextBoxAddress.Text == "" || txtPhoneNumberH.Text == "" || status.Text == "" || pictureBoxProfile.Image == null)
{
MessageBox.Show("Empty fields are detected!. Please fill up all fields");
return;
}
try
{
con.Open();
MySqlCommand cmd2 = new MySqlCommand("UPDATE customer SET mr_mrs = @mr_mrs, short_name = @short_name, full_name = @full_name, nic_number = @nic_number, gender = @gender, address = @address, phone_no_home = @phone_no_home, phone_no_mobile = @phone_no_mobile, image = @image, status = @status, type = @type, nic_frnt = @nic_frnt, nic_back = @nic_back WHERE (nic_number=@nic_number)", con);
MemoryStream ms = new MemoryStream();
pictureBoxProfile.Image.Save(ms, pictureBoxProfile.Image.RawFormat);
byte[] img = ms.ToArray();
MemoryStream ms2 = new MemoryStream();
pictureBox1.Image.Save(ms2, pictureBox1.Image.RawFormat);
byte[] img2 = ms2.ToArray();
MemoryStream ms3 = new MemoryStream();
pictureBox3.Image.Save(ms3, pictureBox3.Image.RawFormat);
byte[] img3 = ms3.ToArray();
cmd2.Parameters.AddWithValue("@mr_mrs", mr_mrs.Text);
cmd2.Parameters.AddWithValue("@short_name", txtShortName.Text);
cmd2.Parameters.AddWithValue("@full_name", txtFullName.Text);
cmd2.Parameters.AddWithValue("@nic_number", textBox1.Text);
cmd2.Parameters.AddWithValue("@gender", gender.Text);
cmd2.Parameters.AddWithValue("@address", richTextBoxAddress.Text);
cmd2.Parameters.AddWithValue("@phone_no_home", txtPhoneNumberH.Text);
cmd2.Parameters.AddWithValue("@phone_no_mobile", txtPhoneNumberM.Text);
cmd2.Parameters.AddWithValue("@status", status.Text);
cmd2.Parameters.AddWithValue("@image", img);
cmd2.Parameters.AddWithValue("@type", comboBox1.Text);
cmd2.Parameters.AddWithValue("@nic_frnt", img2);
cmd2.Parameters.AddWithValue("@nic_back", img3);
cmd2.ExecuteNonQuery();
MessageBox.Show(this, "Customer updated succesfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
con.Close();
ClearData();
}
catch (MySqlException x)
{
MessageBox.Show(x.Message);
con.Close();
}
}
答案 0 :(得分:0)
问题在于Image.Save方法。 而不是:
pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
试试这个:
pictureBox1.Image.Save(ms, Imageformat.Jpeg);