TextRenderer.DrawText()在我的Web应用程序上不起作用?

时间:2011-03-12 08:12:58

标签: c# asp.net

我必须将文本呈现为GDI(而不是GDI +)并将其保存为C#.NET Web应用程序中的图像而不是Windows应用程序,因此我选择了TextRenderer.DrawText()来将文本呈现为GDI,但我是如果鼠标悬停在“当前上下文中不存在名称'TextRenderer'”,则会在TextRenderer下方显示红色内衬的高亮显示消息。我的代码是:

Bitmap Bit = new Bitmap(1000,500);
Graphics g = Graphics.FromImage(Bit);
g.Clear(Color.Red);
TextRenderer.DrawText(graphics, myText, new Font("Ariel", 50, FontStyle.Regular), new Point(20, 20), Color.Black, Color.Gold);
Bit.Save(pathToSaveImg + "image.png", ImageFormat.Png);
Bit.Dispose();

如果有任何感谢,请帮忙。

1 个答案:

答案 0 :(得分:1)

要使用TextRenderer,您需要包含

using System.Windows.Forms;

在代码文件的顶部,并引用项目中的System.Windows.Forms.dll

相关问题