我在这里束手无策,试图找出我做错了什么。我的目标是简单地将图像旋转 90 度并将更改后的完整图像保存回文件系统,然后更新数据库中的缩略图版本。文件系统图像被适当地更改,但是当图像被保存回数据库时,它只保存前 28 个字符。SQL 报告没有错误。
非常感谢我在这里做错了什么的任何想法。提前致谢。
Image image = Image.FromFile(image_path);
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
image.Save(image_path, System.Drawing.Imaging.ImageFormat.Jpeg);
Byte[] thumbnail = null;
System.Drawing.Image thumb = image.GetThumbnailImage(72, 47, () => false, IntPtr.Zero);
thumbnail = imageToByteArray(thumb);
image.Dispose();
string conn = ConfigurationManager.ConnectionStrings["MY_DATABASE"].ConnectionString;
SqlConnection sqlConn = new SqlConnection(conn);
SqlCommand sqlComm = new SqlCommand();
sqlComm = sqlConn.CreateCommand();
sqlComm.CommandText = @"UPDATE MY_TABLE SET pic='@thumbnail' WHERE pic_id= cast(@pic_id As Int) ";
sqlComm.Parameters.Add("@thumbnail", SqlDbType.Image, thumbnail.Length).Value = thumbnail;
sqlComm.Parameters.Add("@pic_id", SqlDbType.Int);
sqlComm.Parameters["@pic_id"].Value = Convert.ToInt32(pic_id);
try
{
sqlConn.Open();
Int32 rowsAffected = sqlComm.ExecuteNonQuery();
context.Response.Write("rowsAffected:" + rowsAffected + "<br/>");
}
catch (Exception ex)
{
context.Response.Write(ex.Message);
}
//sqlConn.Open();
//sqlComm.ExecuteNonQuery();
sqlConn.Close();
context.Response.BinaryWrite(thumbnail);