我想在将图像上传到数据库之前调整图像大小。我该怎么办?代码:
private void SelectBtn_Click(object sender, EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
if (openFile.ShowDialog() == DialogResult.OK)
{
imagePath = openFile.FileName;
}
FileStream fs1 = new FileStream(imagePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
image = new byte[fs1.Length];
fs1.Read(image, 0, Convert.ToInt32(fs1.Length));
fs1.Close();
MemoryStream stream = new MemoryStream(image);
avatarPb.Image = Image.FromStream(stream);
UpdateBtn.Enabled = true;
}
private void UpdateBtn_Click(object sender, EventArgs e)
{
using (SqlConnection connection = new SqlConnection(con))
{
connection.Open();
using (SqlCommand cmd = new SqlCommand("UPDATE UserDetails SET Avatar =@avatar WHERE Email =@email", connection))
{
cmd.Parameters.AddWithValue("@email", Properties.Settings.Default.Email);
SqlParameter prm = new SqlParameter("@avatar", SqlDbType.VarBinary, image.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, image);
cmd.Parameters.Add(prm);
cmd.ExecuteNonQuery();
}
connection.Close();
}
}
我希望在将图像上传到数据库之前调整图像大小。非常感谢!