Question

Background: I am working on a legacy map application using WinForms and .NET4.0. The labels, roads, icons are painted to a separate bitmap called "overlay" apart from the terrain. The background of the overlay is transparent and later will be painted over the terrain bitmap.

The problem is that while painting the text on the bitmap, the text style is being influenced by bitmap background. I show you an example picture of the overlay:

enter image description here

Take a look at the label "abbey" and "white". "White" has been painted on completely transparent background and now looks like if it were written in bold. While "ab" in the "abbey" looks regular text as it has been painted over the icon.

Here is the code that produces the label:

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);
}

I want the text not-bold looking. How can I do that?

Was it helpful?

Solution

As comment earlier says: try using the TextRenderingHint property on your Graphics object to see if it renders the text differently.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top