【问题标题】:How can I set the font colour?如何设置字体颜色?
【发布时间】:2014-04-25 05:11:28
【问题描述】:
我正在使用 Visual C#。在图片上叠加文字时,如何设置字体颜色?
graphicsImage.DrawString(textBox1.Text,
new Font("Arial", 12, FontStyle.Bold)
SystemBrushes.WindowText, new Point(10, 210));
【问题讨论】:
标签:
c#
text
fonts
colors
overlay
【解决方案1】:
尝试像这样使用SolidBrush,你会得到红色字体:
graphicsImage.DrawString(textBox1.Text, new Font("Arial", 12, FontStyle.Bold), new SolidBrush(Color.Red), new Point(10, 210));
【解决方案2】:
没有FontColor 属性,您应该使用正确的Brush。
不要忘记处理 IDisposable,在你的情况下:
using (Brush brush = new SolidBrush(Color.Red)) { // <- Let your text be red
using (Font font = new Font("Arial", 12, FontStyle.Bold)) {
// Paint the text with selected
// font - Arial 12 Bold
// brush - solid red
graphicsImage.Graphics.DrawString(
textBox1.Text, // <- what (text)
font, // <- font
brush, // <- color
new Point(10, 210)); // <- where
}
}