C# 更新图像时,二进制数据将被截断

C# 更新图像时,二进制数据将被截断,c#,sql-server-2008-r2,C#,Sql Server 2008 R2,我在这里绞尽脑汁想弄清楚我做错了什么。我的目标是简单地将图像旋转90度,并将更改后的完整图像保存回文件系统,然后更新数据库中的缩略图版本。文件系统映像会被适当地更改,但是,当映像保存回数据库时,仅会保存前28个字符。SQL报告没有错误 任何关于我在这里做错了什么的想法都将不胜感激。 提前谢谢 Image image = Image.FromFile(image_path); image.RotateFlip(RotateFlipType.Rotate90FlipNone);

我在这里绞尽脑汁想弄清楚我做错了什么。我的目标是简单地将图像旋转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);
Image=Image.FromFile(Image\u路径);
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
保存(图像路径、系统、绘图、成像、图像格式、Jpeg);
字节[]缩略图=空;
System.Drawing.Image thumb=Image.GetThumbnailImage(72,47,()=>false,IntPtr.Zero);
缩略图=imageToByteArray(拇指);
image.Dispose();
string conn=ConfigurationManager.ConnectionString[“我的数据库”]。ConnectionString;
SqlConnection sqlConn=新的SqlConnection(conn);
SqlCommand sqlComm=新的SqlCommand();
sqlComm=sqlConn.CreateCommand();
sqlComm.CommandText=@“更新我的表集pic='@thumbnail',其中pic_id=cast(@pic_id As Int)”;
sqlComm.Parameters.Add(“@thumboil”,SqlDbType.Image,thumboil.Length).Value=thumboil;
添加(“@pic_id”,SqlDbType.Int);
sqlComm.Parameters[“@pic_id”].Value=Convert.ToInt32(pic_id);
尝试
{
sqlConn.Open();
Int32 rowsAffected=sqlComm.ExecuteNonQuery();
context.Response.Write(“rowsAffected:+rowsAffected+”
); } 捕获(例外情况除外) { context.Response.Write(例如Message); } //sqlConn.Open(); //sqlComm.ExecuteNonQuery(); sqlConn.Close(); context.Response.BinaryWrite(缩略图);
MY_表集pic='@thumbnail'

看起来很可疑,为什么要引用

猜测一下,我会说您正在覆盖位图中的标题,字符串“@thumbnail”所对应的任何位模式都对应于您在标题中设置的长度“28”


你太棒了-非常感谢你!!