C# 将水印添加到图像中赢得';不能在服务器上工作,但可以在本地计算机上完美工作?

C# 将水印添加到图像中赢得';不能在服务器上工作,但可以在本地计算机上完美工作?,c#,asp.net-mvc-4,c#-4.0,watermark,C#,Asp.net Mvc 4,C# 4.0,Watermark,我需要一些帮助来找出原因是什么?或者说我在这方面遗漏了什么,因为我很难理解为什么这在我的本地机器上工作,而在服务器上不工作。我有一个C#代码,可以在图像上打印水印,它在我的本地机器上运行得很好,但当我将它应用到我的web主机服务器上时,我正在更新我的网站。它不会打印任何标记。有什么想法吗?下面是我的代码,可以帮助您更好地跟踪它在服务器上无法工作的原因 string watermarkText = "© mywebsite.com"; //Read the File into a Bitmap.

我需要一些帮助来找出原因是什么?或者说我在这方面遗漏了什么,因为我很难理解为什么这在我的本地机器上工作,而在服务器上不工作。我有一个C#代码,可以在图像上打印水印,它在我的本地机器上运行得很好,但当我将它应用到我的web主机服务器上时,我正在更新我的网站。它不会打印任何标记。有什么想法吗?下面是我的代码,可以帮助您更好地跟踪它在服务器上无法工作的原因

string watermarkText = "© mywebsite.com";

//Read the File into a Bitmap.
using (Bitmap bmp = new Bitmap(file.InputStream, false))
{
    using (Graphics grp = Graphics.FromImage(bmp))
    {
        //Set the Color of the Watermark text.
        Brush brush = new SolidBrush(Color.White);

        //Set the Font and its size.
        Font font = new System.Drawing.Font("san-serif", 20, FontStyle.Italic, GraphicsUnit.Pixel);

        //Determine the size of the Watermark text.
        SizeF textSize = new SizeF();
        textSize = grp.MeasureString(watermarkText, font);

        //Position the text and draw it on the image.
        Point position = new Point((bmp.Width - ((int)textSize.Width + 10)), (bmp.Height - ((int)textSize.Height + 10)));
        grp.DrawString(watermarkText, font, brush, position);

        firstfname = Path.GetFileName(file.FileName).ToString();
        newfname = ProdId + firstfname;

        bmp.Save(Path.Combine(Server.MapPath("~/ProductImages/"), newfname));
        con.Open();
        string sqlProductImagesTab = "INSERT INTO [ProdImagesTab]([ProductIdforImages],[ProductImages],[SellerEmail]) Values('" + ProdId + "','" + newfname.Replace("'", "''") + "','" + SellerEmail + "')";
        SqlCommand cmd3 = new SqlCommand(sqlProductImagesTab, con);
        cmd3.CommandType = CommandType.Text;

        cmd3.ExecuteNonQuery();
        cmd3.Dispose();
        con.Close();

    }
}

它的作用是什么?它是否显示未标记的图像?或者该方法完全失败了?是的,sql注入@Rob我正在尝试上传一张图片,希望上传的图片在上传后被加上水印。图片上传得很完美,但是上面没有显示水印。是的,我猜它只显示未标记的图像。这个代码覆盖了原始图像吗?此方法可能会完全失败(很可能是因为数据库连接),但会以静默方式失败。您应该真正知道它是在覆盖原始图像还是将其放置在新位置。。我想这是工作流程的关键部分。无论如何,如果看不到代码的其余部分,就很难进行诊断。正如我提到的,我认为您的代码很可能抛出了一个不可见的异常,因此原始文件不会被替换。您需要对它进行更多的调试,或者在方法中添加一些日志记录,以查看(如果和何时)它是否中断