【问题标题】:Adding Texts on the Image : A generic error occurred in GDI+在图像上添加文本:GDI+ 中发生一般错误
【发布时间】:2012-10-09 13:21:45
【问题描述】:

我想在特定图像上写 3 个文本。 本地主机上没有任何问题。 但是在服务器上,我尝试了一切,但没有任何改变。 总是说:GDI+ 中发生了一般性错误。

如果我一步一步在图像上写文字,我会得到同样的错误。在我添加第一个文本后,第二个和第三个文本无法添加到图像上,因为处理带有第一个文本的图像。

总结:

首先我想在 img1 和 Dispose 上添加 text1。 其次,我想在 img1 和 Dispose 上添加 text2。 第三,我想在 img1 和 Dispose 上添加 text3。

  using (Bitmap bitmapMasterImage = new Bitmap(stringMasterImageName))
            {
                using (Graphics graphicsMasterImage = Graphics.FromImage(bitmapMasterImage))
                {
                    graphicsMasterImage.DrawString(stringText1, new Font("Arial", 20, FontStyle.Bold), new SolidBrush(colorStringColor), new Point(233, 134), stringformatWriteTextFormat);
                    graphicsMasterImage.DrawString(stringText2, new Font("Arial", 20, FontStyle.Bold), new SolidBrush(colorStringColor), new Point(233, 210), stringformatWriteTextFormat);
                    graphicsMasterImage.DrawString(stringText3, new Font("Arial", 20, FontStyle.Bold), new SolidBrush(colorStringColor), new Point(233, 300), stringformatWriteTextFormat);
                }

                Response.Clear();
                Response.ContentType = "image/jpeg";

                using (MemoryStream stream = new MemoryStream())
                {
                    bitmapMasterImage.Save(stream, ImageFormat.Jpeg);
                    bitmapMasterImage.Save(stringOutPutFileName);
                    stream.WriteTo(Response.OutputStream);
                }
            }

谢谢

【问题讨论】:

  • 不确定this 是否有帮助,即在位图的生命周期内保持流打开
  • 失败在哪一行?保存文件时,对吗?
  • 在 localhost 上没有失败。它运行正常。服务器上的错误:GDI+ 中出现一般错误。所以我不知道线路失败了

标签: c# asp.net-mvc asp.net-mvc-3 gdi+


【解决方案1】:

此消息通常出现在

  • 您没有保存文件的写入权限
  • 路径不存在
  • 文件正在使用中

【讨论】:

  • 文件正在使用中。我想在图像上写 3 个文本。在图像上添加第一个文本后,图像正在使用中。这就是为什么我不能添加第二个文本和第三个文本。
【解决方案2】:

检查以确保服务器上的路径设置方式相同(即 stringMasterImageName)。此外,这可能是权限/安全问题。 Look here

【讨论】:

    【解决方案3】:

    尝试关闭画笔流

    using (var brush = new SolidBrush(colorStringColor))
    {
       ...         
    }
    

    或者使用内置画笔,这些不需要关闭。

    graphicsMasterImage.DrawString(stringText1, font, Brushes.Black, new Point(233, 134), stringformatWriteTextFormat);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-02
      • 2011-06-04
      • 2010-11-06
      • 2013-09-26
      • 1970-01-01
      • 1970-01-01
      • 2014-05-07
      相关资源
      最近更新 更多