Text Effects

Text Formatted Text Drawing

Demonstrates how to use shadow and glow effects for drawing text.

Сode Snippet

using (var bitmap = new Bitmap(600, 400, PixelFormat.Format24bppRgb, new RgbColor(255, 255, 255, 255)))
using (var gr = bitmap.GetAdvancedGraphics())
{
    // Draw text with shadow effect
    var textWithShadow = new PlainText("Text with shadow.", gr.CreateFont("Arial", 50))
    {
        Position = new System.Drawing.PointF(50, 50),
        Brush = new SolidBrush(RgbColor.Red),
    };

    textWithShadow.Effect = new Shadow()
    {
        Color = RgbColor.Black,
        OffsetX = 3,
        OffsetY = 3,
        Opacity = 0.5f,
        Size = 2.0f,
    };

    gr.DrawText(textWithShadow);

    // Draw text with glow effect
    var textWithGlow = new PlainText("Text with glow.", gr.CreateFont("Arial", 50))
    {
        Position = new System.Drawing.PointF(50, 250),
        Brush = new SolidBrush(RgbColor.Black),
    };

    textWithGlow.Effect = new Glow()
    {
        Color = RgbColor.Red,
        Opacity = 0.75f,
        Size = 2.0f,
    };

    gr.DrawText(textWithGlow);

    bitmap.Save("TextEffects.png");
}

Output

TextEffects.png

For AI-assisted development: Download Graphics Mill Code Samples XML Catalog