背景:我正在使用 WinForms 和 .NET4.0 开发旧版地图应用程序。标签、道路、图标被绘制到一个单独的位图,称为“覆盖”,与地形不同。叠加层的背景是透明的,稍后将在地形位图上绘制。
问题是在位图上绘制文本时,文本样式受到位图背景的影响。我向您展示了叠加层的示例图片:
看看标签“修道院”和“白色”。“白色”已经画在完全透明的背景上,现在看起来就像是用粗体写的一样。而“abbey”中的“ab”看起来像常规文本,因为它已被绘制在图标上。
这是生成标签的代码:
var bmp = new Bitmap(mapControl.Width, mapControl.Height);
using (var graphics = Graphics.FromImage(bmp))
{
var labelRectangle = GetLabelBorders();
Color labelBackgroundColor = Color.FromArgb(128, Color.FromName("LightPink"));
SolidBrush sb = new SolidBrush(labelBackgroundColor);
graphics.FillRectangle(sb, labelRectangle );
graphics.DrawRectangle(WhitePen, labelRectangle .X, labelRectangle .Y,
labelRectangle .Width - 1, labelRectangle .Height - 1);
Font timesnew8 = new Font("TimesNew", 8);
StringFormat strForm = new StringFormat();
strForm.Alignment = StringAlignment.Near;
graphics.DrawString("abbey", timesnew8, Brushes.Black, labelRectangle , strForm);
}
我希望文本看起来不粗体。我怎样才能做到这一点?